Database provider in dot net

Posted by Hidayat S under ADO.NET on 3/31/2015 | Points: 10 | Views : 427 | Status : [Member] | Replies : 2
Is it possible to open two different database provider in one application at a time ?

warm Regards,
Hidayat S
Sr. Software Developer
PS Solutions Pvt. Ltd
Pune-411038



Responses

Posted by: Rajnilari2015 on: 3/31/2015 [Member] [Microsoft_MVP] [MVP] Platinum | Points: 25

Up
0
Down
Yes it is possible by using the Provider Model. Sometimes back I have written an article about Provider Model in dotnetfunda ( http://www.dotnetfunda.com/articles/show/2306/let-us-learn-provider-design-pattern )

All you have to do is

<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 you can get the provider factory by name:

DbProviderFactory factory =

DbProviderFactories.GetFactory(providerName);

connection = factory.CreateConnection();


A discussion about the same is in StackOverflow ( http://stackoverflow.com/questions/29361390/can-we-open-two-db-providers-at-a-time )


For more information you can refer:

Provider Model

https://msdn.microsoft.com/en-us/library/aa479020.aspx

http://www.dotnetfunda.com/articles/show/2306/let-us-learn-provider-design-pattern

http://dotnetslackers.com/articles/designpatterns/HowToWriteAProviderModel.aspx

http://www.codemag.com/Article/0711081

Obtaining a DbProviderFactory

https://msdn.microsoft.com/en-us/library/dd0w4a2z%28v=vs.110%29.aspx

Hope that helps.



--
Thanks & Regards,
RNA Team

Hidayat S, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sagabizsolutions on: 3/31/2015 [Member] Starter | Points: 25

Up
0
Down
Use the below code and it wil be work fine.
<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>
For more visti:http://stackoverflow.com/questions/29361390/can-we-open-two-db-providers-at-a-time

Thanks & Regards,
Saga Biz Solutions


Hidayat S, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response