开发者

Connecting to SQL Server, Oracle, DB2 and MySQL simultaneously using ADO.NET?

I'm relatively new to .NET but I'm trying to determine 开发者_如何学JAVAif it's possible to have a single .NET 4 application connect to multiple vendor databases simultaneously (SQL Server, Oracle, DB2 and MySQL) using ADO.NET and execute queries simultaneously?

All the examples I've found so far talk about connecting to only one database at a time. Thanks!


You just need 4 connections strings and 4 separate ADO Connection objects. And then what SLaks said about async queries to do them simultaneously, if you truly want them running in parallel.


You can execute two queries the same way you execute one query.

If you want them to execute two queries at once, you'll need to make asynchronous queries or use threads.


The ADO.NET framework defines an abstract set of 'DbXXX' classes like DbConnection,DbCommand etc, which are implemented by various database providers such as

  1. System.Data.SqlClient.SqlConnection' in the System.Data.dll for Sql Server

  2. 'Oracle.DataAccess.Client.OracleConnection' in the Oracle.DataAccess.dll (ODP.NET provider) for Oracle

  3. 'MySql.Data.MySqlClient.MySqlConnection' in the MySql.Data.dll for MySql etc

    You then need to design your apllication against the abstract set of classes and use appropriate implementations wherever required. Most of the queries should work against all the backends but there will obviously be backend specific tweaks, not to mention stored procedure calls.

Alternatively you could use an ORM (Entity Framework, Telerik OpenAccess ORM, NHibernate etc) and abstract much of this difference to the ORM. Although I am not sure you can use a single entity model (in EF) against multiple backends.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜