2012-07-24 63 views
0

IHAVE閱讀接受的答案這個帖子:ExecuteReader requires an open and available Connection. The connection's current state is Connecting.NET連接池領土

我存儲在數據庫表中的幾個連接字符串。我在想這樣做這樣的事情:

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 

我遊蕩,如果這將導致與連接池機制的問題,因爲我有效地封裝了一些邏輯的一類用於連接到這些數據庫。

回答

0

您的類的實例不會影響SQL Server的連接字符串池的能力。只要連接字符串聲明連接池並且連接字符串相同,SQL服務器就會嘗試使用當前連接而不創建新連接。有關更多信息,請參閱MSDN