问题描述
IHAVE阅读接受的答案这个职位:ExecuteReader需要一个开放和可用的连接。连接的当前状态,连接
Ihave read the accepted answer to this post: ExecuteReader requires an open and available Connection. The connection's current state is Connecting
我具有被存储在数据库表中的几个连接字符串。我在想这样做这样的事情:
I have a few connection strings that are stored in a database table. I was thinking about doing something like this:
Public class classConnection
private con1 As dbConnection
private strConnectionString As String
private intType As Integer
Public Sub New()
con1 = New SQLConnection({connectionstring})
End Sub
Public Sub getConnectionStringByDescription()
'Connect to con1 and get connection string
'Set the connection string property
'Set the database type e.g. Oracle
End Sub
Public Sub getConnectionStringByStatus()
'Connect to con1 and get connection string
'Set the database type e.g. Oracle
End Sub
Public Function getConnection() As dbConnection
If intType=1 Then
return New SQLConnection(strConnectionString)
ElseIf intType=2 Then
return New OracleConnection(strConnectionString)
End If
End Function
我是游荡,如果这会导致因为我有效封装了一些逻辑的一类用于连接到这些数据库连接池机制的问题。
I am wandering if this will cause problems with the connection pool mechanism as I am effectively encapsulating some of the logic in a class for connecting to these databases.
推荐答案
你的类的实例,将不会影响SQL Server的abililty汇集连接字符串。只要连接字符串声明连接池和连接字符串均相同,则SQL Server将尝试使用当前的连接,而无需创建新的。请参见了解详情。
The instances of your class will not affect SQL server's abililty to pool connection strings. As long as the connection strings declare connection pooling and the connection strings are the same, SQL server will try to use current connections without creating new ones. See MSDN for more information.
这篇关于.NET连接池领土的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!