2017-02-04 83 views
0

超时已过期。在从池中获取连接之前已超时。出现这种情况可能是因为所有池连接使用,最大池大小达到.net api连接错误

我有这个错误的最大时间我的连接字符串是

我有这个错误

和最大时间我这样的api

System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); 
     //string valuess = Commanfunction.logintokencheck(user_id, token); 
     try 
     {     
      //if (valuess == "True") 
      //{ 
       DataTable dt = new DataTable(); 
       using (SqlCommand cmd = new SqlCommand("SELECT * FROM [nwt].[usermessage] where [to_user] = '" + user_id + "' AND [msg_user_type] ='inbox' AND [reviwe] =1 AND ([status]='active' OR [status]='keep')", sconn)) 
       { 
        sconn.Open(); 
        SqlDataAdapter da = new SqlDataAdapter(cmd); 
        da.Fill(dt); 

        List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); 
        Dictionary<string, object> row; 
        string x = "{\"status\":\"200ok\",\"reviewcount\":" + dt.Rows.Count; 
        // string y= serializer.Serialize(x); 
        //foreach (DataRow dr in dt.Rows) 
        //{ 
        // row = new Dictionary<string, object>(); 
        // foreach (DataColumn col in dt.Columns) 
        // { 
        //  row.Add(col.ColumnName, dr[col]); 
        // } 
        // rows.Add(row); 
        //} 
        //string z = serializer.Serialize(rows); 
        return new RawJsonActionResult(x + "}"); 
        //return (x + "\"countries\":" + z + "}"); 

       } 

我该如何解决这个错误,并优化我的API。为解决方案

+0

rahul

+0

什么是'sconn'?这里缺少很多信息。 –

+0

SqlConnection sconn = new SqlConnection(ConfigurationManager.ConnectionStrings [“ConnString”]。ConnectionString); – rahul

回答

0

可能会尝试在连接字符串中定义诸如以下

添加名称= “CONNSTRING” 的connectionString =“数据源= 53.127.121.91池大小;初始目录= nhybridtewft;用户ID = SA;密码= admin; Integrated Security = False; Max Pool Size = 1024; Pooling = true; multipleActiveResultSets = true;“ providerName =“System.Data.SqlClient”

您可以尝试增加数字并查看错误是否消失。我猜你可以声明的最大池大小是32767.