Click here to Skip to main content
15,034,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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)
Posted

Close Your All Connection Properly


C#
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();
}
   
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;



C#
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;


    }
}
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900