使用 ADO.NET 同时连接到 SQL Server、Oracle、DB2 和 MySQL?
我对 .NET 比较陌生,但我试图确定是否可以让单个 .NET 4 应用程序使用 ADO.NET 同时连接到多个供应商数据库(SQL Server、Oracle、DB2 和 MySQL)并同时执行查询?
到目前为止,我发现的所有示例都讨论一次仅连接到一个数据库。 谢谢!
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?
All the examples I've found so far talk about connecting to only one database at a time.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您只需要 4 个连接字符串和 4 个单独的 ADO Connection 对象。然后 SLAks 所说的异步查询可以同时执行,如果你真的希望它们并行运行的话。
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.
ADO.NET 框架定义了一组抽象的“DbXXX”类,例如 DbConnection,DbCommand 等,它们由各种数据库提供程序实现,例如
System.Data.SqlClient.SqlConnection'
Oracle 的 Oracle.DataAccess.dll(ODP.NET 提供程序)中的“Oracle.DataAccess.Client.OracleConnection”
适用于 MySql 等的 MySql.Data.dll 中的“MySql.Data.MySqlClient.MySqlConnection”
然后,您需要根据抽象类集设计应用程序,并在需要时使用适当的实现。大多数查询应该适用于所有后端,但显然会有后端特定的调整,更不用说存储过程调用了。
或者,您可以使用 ORM(实体框架、Telerik OpenAccess ORM、NHibernate 等)并将大部分差异抽象到 ORM。尽管我不确定您是否可以针对多个后端使用单个实体模型(在 EF 中)。
The ADO.NET framework defines an abstract set of 'DbXXX' classes like DbConnection,DbCommand etc, which are implemented by various database providers such as
System.Data.SqlClient.SqlConnection' in the System.Data.dll for Sql Server
'Oracle.DataAccess.Client.OracleConnection' in the Oracle.DataAccess.dll (ODP.NET provider) for Oracle
'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.