Daniel Little Coding Blog
Daniel Little Coding Blog

A blog about .net development and the web.

Daniel Little
Author

Daniel Little (lavinski) is a Brisbane based software developer.

Share


Our Newsletter


Like this blog? Get each new post as soon it's posted.

Tags


Twitter


Using ProviderName to get the database connection

Daniel LittleDaniel Little

When setting your connection string in a .NET config file you can make use of the providerName attribute by using DbProviderFactories.GetFactory and passing it the provider name.

var connectionStringSettings = ConfigurationManager.ConnectionStrings["DefaultConnection"];

connection = DbProviderFactories.GetFactory(connectionStringSettings.ProviderName).CreateConnection();
connection.ConnectionString = connectionStringSettings.ConnectionString;
connection.Open();
Daniel Little
Author

Daniel Little

Daniel Little (lavinski) is a Brisbane based software developer.

Comments