简体   繁体   English

使用ADO.NET同时连接到SQL Server,Oracle,DB2和MySQL?

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

I'm relatively new to .NET but I'm trying to determine if 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? 我对.NET相对较新,但是我试图确定是否可以使用ADO.NET将单个.NET 4应用程序同时连接到多个供应商数据库(SQL Server,Oracle,DB2和MySQL)并同时执行查询?

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. 您只需要4个连接字符串和4个单独的ADO Connection对象。 And then what SLaks said about async queries to do them simultaneously, if you truly want them running in parallel. 然后,如果您确实希望异步查询并行运行,那么SLaks所说的关于异步查询的问题要同时执行。

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 ADO.NET框架定义了一组抽象的“ DbXXX”类,例如DbConnectionDbCommand等,这些类由各种数据库提供程序实现,例如

  1. System.Data.SqlClient.SqlConnection' in the System.Data.dll for Sql Server Sql Server的System.Data.dll中的System.Data.SqlClient.SqlConnection'
  2. 'Oracle.DataAccess.Client.OracleConnection' in the Oracle.DataAccess.dll (ODP.NET provider) for Oracle Oracle的Oracle.DataAccess.dll(ODP.NET提供程序)中的“ Oracle.DataAccess.Client.OracleConnection”
  3. 'MySql.Data.MySqlClient.MySqlConnection' in the MySql.Data.dll for MySql etc MySql等的MySql.Data.dll中的'MySql.Data.MySqlClient.MySqlConnection'

    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. 或者,您可以使用ORM(实体框架,Telerik OpenAccess ORM,NHibernate等)并将这种差异中的大部分抽象到ORM中。 Although I am not sure you can use a single entity model (in EF) against multiple backends. 尽管我不确定您可以针对多个后端使用单个实体模型(在EF中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM