0

在静态构造函数中,我检查是否可以打开与所有数据库的连接,然后保留 ConnectionStrings 的静态副本,然后在需要时使用它。

现在,如果我创建

私有静态列表 <OleDbConnection> _connections;

并将所有打开的连接存储为打开的连接?我可以在应用程序打开之前使用这些连接吗?这样做有什么坏处吗?

4

1 回答 1

5

This is already done for you by the system using connection pools.

http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbconnection.aspx

To deploy high-performance applications, you must use connection pooling. When you use the .NET Framework Data Provider for OLE DB, you do not have to enable connection pooling because the provider manages this automatically. For more information about how to use connection pooling with the .NET Framework Data Provider for OLE DB, see OLE DB, ODBC, and Oracle Connection Pooling (ADO.NET) (https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/ole-db-odbc-and-oracle-connection-pooling).

于 2012-02-21T22:18:19.247 回答