连接池错误 [英] Connection Pool Error

查看:103
本文介绍了连接池错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



当我从多个用户调用时,我的网络服务收到以下错误。

我检查了我的代码我已经在finally {}活动中关闭了所有的sql连接。

请帮忙,因为我面临很多问题。



5/30 / 2014 9:42:40 AM_METHOD_ExceptionCount()_ NEM__ERROR_Timeout已过期。从池中获取连接之前经过的超时时间。发生这种情况可能是因为所有池连接都在使用且达到了最大池大小。在System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)处__LINE_0_stack_

在System.Data.ProviderBase.DbConnectionClosed。 OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)

at System.Data.SqlClient.SqlConnection.Open()

at LT_APP_WCF_14.Service1.ExceptionCount(String nem)





5/30/2014 9:42:29 AM_METHOD_ExceptionCount()_ NEM__ERROR_Timeout已过期。从池中获取连接之前经过的超时时间。发生这种情况可能是因为所有池连接都在使用且达到了最大池大小。在System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)处__LINE_0_stack_

在System.Data.ProviderBase.DbConnectionClosed。 OpenConnection(DbConnection outerConnection,DbConnectionFactory connectionFactory)

at System.Data.SqlClient.SqlConnection.Open()

at LT_APP_WCF_14.Service1.ExceptionCount(String nem)

Hello all,

I am receiving below error in my web service when called from multiple users.
I have checked my code i have closed all my sql connections in finally{} event.
Kindly help as i am facing lot of issues.

5/30/2014 9:42:40 AM_METHOD_ExceptionCount()_NEM__ERROR_Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached._LINE_0_stack_ at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at LT_APP_WCF_14.Service1.ExceptionCount(String nem)


5/30/2014 9:42:29 AM_METHOD_ExceptionCount()_NEM__ERROR_Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached._LINE_0_stack_ at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at LT_APP_WCF_14.Service1.ExceptionCount(String nem)

推荐答案

正确关闭所有连接





Close Your All Connection Properly


SqlConnection conn = new SqlConnection("CONNECTION_STRING_HERE");

try
{
    conn.Open();

    //Perform DB operation here i.e. any CRUD operation

    //Conn.Close();  //This should never be here
}
catch (Exception ex)
{
    //Handle exception, perhaps log it and do the needful
}
finally
{
    //Connection should always be closed here so that it will close always
    conn.Close();
}


我已经像你建议的那样使用它了。



我有图像创建实用程序它从html创建图像。

我怀疑同样的实用程序是否会产生问题。



锁(储物柜)

{



//调用方式写入图片



步骤+ =通话wbcapture ---开始+ DateTime.Now.ToString()+ main_id + Environment.NewLine;



WBCapture(applicant22,AppFormNo);

WBCapture(guarantor22,AppFormNo);

WBCapture(co_applicant22,AppFormNo);

WBCapture(参见22,AppFormNo);

WBCapture(asset22 ,AppFormNo);

WBCapt ure(extra6,AppFormNo);

步骤+ =调用wbcapture ---结束+ DateTime.Now.ToString()+ main_id + Environment.NewLine;

}



步数+ =插入图像数据 - 锁定 - 开始+ DateTime.Now.ToString()+ main_id + Environment.NewLine;

lock(locker)

{



for(int i = 0;我< imagelist.Count(); i ++)

{

// if(imagelist [0]!= null&& imagelist [1]!= null&& imagelist [2]! = null&& imagelist [3]!= null&& imagelist [4]!= null&& imagelist [5]!= null)

// {

步骤+ =图像名称+ imagelist [i] +计数+ imagelist.Count()+ Environment.NewLine;

#region插入图像记录

SqlConnection con98 = new SqlConnection(path);

SqlCommand cmd98 = new SqlCommand(InsertImage,con98);

cmd98.CommandType = CommandType.StoredProcedure;

//cmd98.Parameters.AddWithValue(\"@name,imgname +_ APPLICATION_FORM_WITH_OTHER PAGES_+ page +_+ DateTime.Now.ToS tring(ddMMyyyyHHmmss)+.jpg);

cmd98.Parameters.AddWithValue(@ doc_name,imagelist [i]);

cmd98.Parameters。 AddWithValue(@ doc_type,APPLICATION_FORM_WITH_OTHER_PAGES);

if(AppFormNo ==||| main_id ==)

{

cmd98.Parameters.AddWithValue(@ appno,AppFormNo2);

cmd98.Parameters.AddWithValue (@main_id,main_id2);

}

else

{

cmd98.Parameters.AddWithValue( @ appno,AppFormNo);

cmd98.Parameters.AddWithValue(@ main_id,main_id);

}



cmd98.Parameters.AddWithValue(@ flag,);

con98.Open();

if(imagelist [i]!= null)

cmd98.ExecuteNonQuery();



con98.Close();



#endregion

//}





}

步骤+ =更新到2旗帜---+ main_id + Environment.NewLine;

Array.Clear( imagelist,0,imagelist.Length);

UpdateFlag2(main_id,AppFormNo);

}

步骤+ =插入图像数据 - LOCK-结束+ DateTime.Now.ToString()+ main_id + Environment.NewLine;

// timer3.Enabled = true;







I have already used it like u suggested.

I have image creation utility it creates images from html.
I am doubted same utility is creating problem.

lock (locker)
{

//call method to write in image

steps += "calling wbcapture--- Start "+DateTime.Now.ToString() + main_id + Environment.NewLine;

WBCapture(applicant22,AppFormNo);
WBCapture(guarantor22, AppFormNo);
WBCapture(co_applicant22, AppFormNo);
WBCapture(refer22, AppFormNo);
WBCapture(asset22, AppFormNo);
WBCapture(extra6, AppFormNo);
steps += "calling wbcapture--- End " + DateTime.Now.ToString() + main_id + Environment.NewLine;
}

steps += "INSERT IMAGE DATA --LOCK- Start "+DateTime.Now.ToString() + main_id + Environment.NewLine;
lock (locker)
{

for (int i = 0; i < imagelist.Count(); i++)
{
//if (imagelist[0] != null && imagelist[1] != null && imagelist[2] != null && imagelist[3] != null && imagelist[4] != null && imagelist[5] != null)
//{
steps += "Image Name " + imagelist[i] + " Count " + imagelist.Count() + Environment.NewLine;
#region insert image record
SqlConnection con98 = new SqlConnection(path);
SqlCommand cmd98 = new SqlCommand("InsertImage", con98);
cmd98.CommandType = CommandType.StoredProcedure;
//cmd98.Parameters.AddWithValue("@name", imgname + "_APPLICATION_FORM_WITH_OTHER PAGES_" + page + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".jpg");
cmd98.Parameters.AddWithValue("@doc_name", imagelist[i]);
cmd98.Parameters.AddWithValue("@doc_type", "APPLICATION_FORM_WITH_OTHER_PAGES");
if (AppFormNo == "" || main_id == "")
{
cmd98.Parameters.AddWithValue("@appno", AppFormNo2);
cmd98.Parameters.AddWithValue("@main_id", main_id2);
}
else
{
cmd98.Parameters.AddWithValue("@appno", AppFormNo);
cmd98.Parameters.AddWithValue("@main_id", main_id);
}

cmd98.Parameters.AddWithValue("@flag", "");
con98.Open();
if(imagelist[i]!=null)
cmd98.ExecuteNonQuery();

con98.Close();

#endregion
//}


}
steps += "update to 2 flag--- " + main_id + Environment.NewLine;
Array.Clear(imagelist,0 , imagelist.Length);
UpdateFlag2(main_id, AppFormNo);
}
steps += "INSERT IMAGE DATA --LOCK- End " + DateTime.Now.ToString() + main_id + Environment.NewLine;
// timer3.Enabled = true;



public void WBCapture(string str,string appNo)
   {

           if (appCheck == appNo)
           {

           }
           else
           {

               if (verify < 6)
               {


                   verify++;

                   WebBrowser wb = new WebBrowser();
                   wb.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);

                   //wb.DocumentCompleted == new WebBrowserDocumentCompletedEventHandler(wb_DocumentCompleted);

                   wb.ScrollBarsEnabled = false;
                   wb.Width = 1280;
                   wb.Height = 960;
                   wb.DocumentText = str;
                   //while (ThreadCompleted != "YES")
                   //{
                   //}

               }
               else
               {
                   appCheck = appNo;
                   verify = 0;
               }
           }



       // Or you can navigate to:
       // wb.Navigate("http://mydocmentsurl.com");
   }










void wb_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{

    try
    {
        WebBrowser wb = (WebBrowser)sender;
        page++;
        using (Graphics graphics = wb.CreateGraphics())
        using (Bitmap bitmap = new Bitmap(wb.Width, wb.Height, graphics))
        //using (Bitmap bitmap = new Bitmap(800, 600, graphics))
        //IntPtr p = IntPtr.Zero;
        // Bitmap bitmap=new Bitmap (20000,30000,0,System.Drawing.Imaging.PixelFormat.Format1bppIndexed,p);
        {
            Rectangle bounds = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
            //Rectangle bounds = new Rectangle(0,0,800,600);
            wb.DrawToBitmap(bitmap, bounds);
            if (page == 7)
            {
                page = 1;
            }

            double epoch = (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;

            string r = epoch.ToString();

            string img = imgname + "_APPLICATION_FORM_WITH_OTHER_PAGES_" + page + "_" + r + ".jpg";

            bitmap.Save(@"" + txt_path.Text + img, ImageFormat.Jpeg);

            if (File.Exists(@"" + txt_path.Text + img))
            {
                imagelist[page - 1] = img;

                //#region insert image record



                //SqlConnection con98 = new SqlConnection(path);
                //SqlCommand cmd98 = new SqlCommand("InsertImage", con98);
                //cmd98.CommandType = CommandType.StoredProcedure;
                ////cmd98.Parameters.AddWithValue("@name", imgname + "_APPLICATION_FORM_WITH_OTHER PAGES_" + page + "_" + DateTime.Now.ToString("ddMMyyyyHHmmss") + ".jpg");
                //cmd98.Parameters.AddWithValue("@doc_name", img);
                //cmd98.Parameters.AddWithValue("@doc_type", "APPLICATION_FORM_WITH_OTHER_PAGES");
                //if (AppFormNo == "" || main_id == "")
                //{
                //    cmd98.Parameters.AddWithValue("@appno", AppFormNo2);
                //    cmd98.Parameters.AddWithValue("@main_id", main_id2);
                //}
                //else
                //{
                //    cmd98.Parameters.AddWithValue("@appno", AppFormNo);
                //    cmd98.Parameters.AddWithValue("@main_id", main_id);
                //}

                //cmd98.Parameters.AddWithValue("@flag", "");
                //con98.Open();
                //cmd98.ExecuteNonQuery();

                //con98.Close();


                //#endregion
            }

            //if (page == 6) {
            //    ThreadCompleted = "YES";
            //}

            #region make 4 to 1 file

            //TO MAKE 4 TO 1 IMAGE

            //createPanel(filePath);

            #endregion


        }

    }
    catch (Exception qq)
    {
        ErrorLog.Log(qq.Message, main_id, "", "wb_DocumentCompleted", qq.StackTrace);
        timer1.Enabled = false;
        timer2.Enabled = true;


    }
}


这篇关于连接池错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆