2012-07-25 80 views
1

的最大數量這種方法會導致錯誤的文件,以充分與此錯誤:連接池已達到連接

Connection Pool has reached the maximum number of connections 

public static int IsValidPortalUser(string p_u, string p_p) { 
      int item = 0; 
      using (IfxConnection ifxConnection = new IfxConnection(DB_Connection.connectionString)) 
      { 
       IfxCommand ifxCommand = new IfxCommand(); 
       string str = DB_Connection.My_Decryption_2(p_p); 
       try 
       { 
        if (ifxConnection.State == 0) 
        { 
         ifxConnection.Open(); 
        } 
        DB_Connection.DBCmd = new IfxCommand(); 
        DB_Connection.DBCmd.Connection = ifxConnection; 
        DB_Connection.DBCmd.CommandText = "SELECT nvl(emp_num,0) FROM htoemp WHERE username = ? AND DECRYPT_CHAR(password, '78dfdf') = ? "; 
        DB_Connection.DBCmd.Parameters.Add("user_name", p_u); 
        DB_Connection.DBCmd.Parameters.Add("password", str); 

        IfxDataReader ifxDataReaders = ifxCommand.ExecuteReader(); 
        using (ifxDataReaders) 
        { 
         if (ifxDataReaders.Read()) 
         { 
          item = (int)ifxDataReaders[0]; 
         } 
         ifxDataReaders.Close(); 
        } 
       } 
       catch (ApplicationException applicationException) 
       { 
       } 
       ifxConnection.Close(); 
      } 
      return item; 
     } 

Error Message:Connection Pool has reached the maximum number of connections. Stack Trace : at IBM.Data.Informix.IfxConnectionPool.ReportOpenTimeOut() 
    at IBM.Data.Informix.IfxConnectionPool.Open(IfxConnection connection) 
    at IBM.Data.Informix.IfxConnPoolManager.Open(IfxConnection connection) 
    at IBM.Data.Informix.IfxConnection.Open() 
    at DB_Connection_s.DB_Connection.IsValidPortalUser(String p_u, String p_p) 
    at LoginSystem.LoginPage_ar.ValidateUser(String UserName, String Password) in H:\LoginSystem\LoginSystem\LoginPage_ar.aspx.cs:line 20 
    at LoginSystem.LoginPage_ar.ibtn_login_Click(Object sender, ImageClickEventArgs e) in H:\LoginSystem\LoginSystem\LoginPage_ar.aspx.cs:line 33 
    at System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) 
    at System.Web.UI.WebControls.ImageButton.RaisePostBackEvent(String eventArgument) 
    at System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) 
    at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) 
    at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) 
    at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

現在我設定Max Pool Size=400代替Max Pool Size=200

並且直到現在沒有這種類型的錯誤,但我想知道爲什麼這種方法會導致這個問題。

+0

什麼是DB_Connection?假設有什麼地方出錯,因爲ifxConnection被創建,打開和銷燬,但從未使用過。 – Steve 2012-07-25 10:40:15

+1

'ifxConnection'確實應該被'using'關閉;我可以問,雖然;什麼是'DB_Connection.conn'?以防萬一它是相關的......另外:作爲一般事情:爲什麼catch/swallow ApplicationException? – 2012-07-25 10:42:07

+0

你也創建一個ifxCommand,但是sql字符串被傳遞給另一個命令。然後代碼執行ifxCommand。我懷疑這裏的dataadapter會返回什麼。 – Steve 2012-07-25 10:43:57

回答

1

這是一個在黑暗中實拍,所以,讓我知道,如果有新的變化

public static int IsValidPortalUser(string p_u, string p_p) 
{ 
    int item = 0; 
    using (IfxConnection ifxConnection = new IfxConnection(DB_Connection.connectionString)) 
    { 
     IfxCommand ifxCommand = new IfxCommand(); 
     string str = DB_Connection.My_Decryption_2(p_p); 
     try 
     { 
      if (ifxConnection.State == 0) 
       ifxConnection.Open(); 
      ifxCommand.Connection = idxConnection; 
      ifxCommand.CommandText = "SELECT nvl(emp_num,0) FROM htoemp WHERE username = ? 
             AND DECRYPT_CHAR(password, '78dfdf') = ? "; 
      ifxCommand.Parameters.AddWithValue("user_name", p_u); 
      ifxCommand.Parameters.AddWithValue("password", str); 
      IfxDataReader ifxDataReaders = ifxCommand.ExecuteReader(); 
      using (ifxDataReaders) 
      { 
       if (ifxDataReaders.Read()) 
       { 
        item = (int)ifxDataReaders[0]; 
       } 
       ifxDataReaders.Close(); 
      } 
     } 
    } 
    return item; 
} 

另外,根據您的Informix版本,字符串密碼是reserved keyword