.NET连接池区域

时间:2012-07-24 12:54:29

标签: asp.net vb.net

我已阅读此帖的接受答案:ExecuteReader requires an open and available Connection. The connection's current state is Connecting

我有一些存储在数据库表中的连接字符串。我正在考虑做这样的事情:

    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

如果这会导致连接池机制出现问题,我会徘徊,因为我有效地将类中的一些逻辑封装起来以连接到这些数据库。

1 个答案:

答案 0 :(得分:0)

您的类的实例不会影响SQL服务器对池连接字符串的依赖性。只要连接字符串声明连接池并且连接字符串相同,SQL Server就会尝试使用当前连接而不创建新连接。有关详细信息,请参阅MSDN