TAGS :Viewed: 13 - Published at: a few seconds ago

[ Can we open two DB providers at a time? ]

Wondering if it is ever possible to open two database providers in a single application at a time?

I know the provider model, but that will help to provide one db provider initialization at one time. How can we make two/ multiple?

Or any other way?

Answer 1

Yes, this is possible here is an example:

      <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=" />
      <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=, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />

Then you can get the provider factory by name:

DbProviderFactory factory =

            connection = factory.CreateConnection();

More information you can find here: https://msdn.microsoft.com/en-us/library/dd0w4a2z%28v=vs.110%29.aspx