Code for opening two different database provider in one application at a time using Provider Model

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 208
<system.data>

<DbProviderFactories>

<remove invariant="MySql.Data.MySqlClient"></remove>

<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0" />

<remove invariant="System.Data.SqlServerCe.4.0" />

<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />

</DbProviderFactories>

</system.data>



Then we can get the provider factory by name:

DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
connection = factory.CreateConnection();

Comments or Responses

Posted by: Vishalneeraj-24503 on: 1/4/2016 Level:Platinum | Status: [Member] [MVP] | Points: 10
Rajnilari2015 - Kindly clarify please.
DbProviderFactory factory = DbProviderFactories.GetFactory(providerName);
connection = factory.CreateConnection();

Posted by: Rajnilari2015 on: 1/4/2016 Level:Platinum | Status: [Member] [Microsoft_MVP] [MVP] | Points: 10
@Vishalneeraj-24503 Sir, long time back I wrote an article on Provider Design Pattern ( http://www.dotnetfunda.com/articles/show/2306/let-us-learn-provider-design-pattern ). Hope you will enjoy. Please let me know for further clarification.

Thanks

Login to post response