SQL debugging + Connection Pooling = Timeout expired exception

M

Mike Kiefer

I originally started having problems with this in a different application
but after scouring every bit of code for missing connection Close()
statements or Dispose() statements, I was convinced that this had to be a
bug that only showed up with with both Sql Debugging on and connection
pooling in use. The following app will reproduce the problem consistently as
indicated in the comments.

Hopefully someone from Microsoft will pick this up and put it to good use in
order to solve the problem in the next release.

Mike

////////////////////////////////////////////////////////////////////////////
/
/// Under the proper conditions, this program will repeatedly generate the
/// following error after 100 iterations:
///
/// 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.
///
/// This error will occur ONLY if SQL debugging is enabled under the project
/// settings (Configuration Properties->Debugging->Enabled SQL Debugging =
true)
/// AND connection pooling is enabled (by default or if "pooling=true"
/// in the connection string). If EITHER of these options are turned off,
the
/// program successfully completes all 500 iterations. Otherwise, the error
will occur
/// at the start of iteration #100.
///
/// Tested using SQL Server 2000 SP3, Visual Studio .NET 2003, and
/// the .NET Framework version 1.1. The problem originally appeared prior to
/// installing SQL Server SP3, so other combinations may also be a problem.
////////////////////////////////////////////////////////////////////////////
/
using System;
using System.Data;
using System.Data.SqlClient;

namespace SqlDebuggingTest2
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
for (int i = 0 ; i < 500; i++)
{
Console.Out.WriteLine("Iteration # {0}", i);
SqlConnection conn = new
SqlConnection("pooling=true;Server='(local)';Integrated
Security=true;Initial Catalog=northwind;Application Name=Testing;");
try
{
conn.Open();

SqlCommand cmdToExecute = new SqlCommand();
try
{
cmdToExecute.CommandText = "CustOrdersOrders";
cmdToExecute.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
try
{
cmdToExecute.Connection = conn;
string customerId = "QUICK";;
cmdToExecute.Parameters.Add(new SqlParameter("@CustomerID",
customerId));

DataSet ds = new DataSet("foo");
try
{
adapter.Fill(ds);
}
finally
{
if (ds != null)
ds.Dispose();
}
}
finally
{
if (adapter != null)
adapter.Dispose();
}
}
finally
{
if (cmdToExecute != null)
cmdToExecute.Dispose();
}
}
finally
{
if (conn != null)
{
conn.Close();
conn.Dispose();
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("{0}", ex.ToString());
Console.WriteLine("Program terminated."); // line exists to set
breakpoint on.
}

}
}
}
 
Y

Yan-Hong Huang[MSFT]

Hello Mike,

Thanks for posting in the group.

I noticed that the question is also posted in vsnet.debugging group. I have
replied it there. Please check my reply when you have free time. If you
have any more concerns, please post there and I will follow up you on it.

Thanks again for participating the community.

Best regards,
Yanhong Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
!From: "Mike Kiefer" <[email protected]>
!Subject: SQL debugging + Connection Pooling = Timeout expired exception
!Date: Wed, 24 Sep 2003 16:55:00 -0500
!Lines: 123
!X-Priority: 3
!X-MSMail-Priority: Normal
!X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
!X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
!Message-ID: <O#[email protected]>
!Newsgroups:
microsoft.public.vsnet.debugging,microsoft.public.dotnet.framework.adonet
!NNTP-Posting-Host: user-0cet19d.cable.mindspring.com 24.238.133.45
!Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:62049
microsoft.public.vsnet.debugging:3516
!X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
!
!I originally started having problems with this in a different application
!but after scouring every bit of code for missing connection Close()
!statements or Dispose() statements, I was convinced that this had to be a
!bug that only showed up with with both Sql Debugging on and connection
!pooling in use. The following app will reproduce the problem consistently
as
!indicated in the comments.
!
!Hopefully someone from Microsoft will pick this up and put it to good use
in
!order to solve the problem in the next release.
!
!Mike
!
!///////////////////////////////////////////////////////////////////////////
/
!/
!/// Under the proper conditions, this program will repeatedly generate the
!/// following error after 100 iterations:
!///
!/// 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.
!///
!/// This error will occur ONLY if SQL debugging is enabled under the
project
!/// settings (Configuration Properties->Debugging->Enabled SQL Debugging =
!true)
!/// AND connection pooling is enabled (by default or if "pooling=true"
!/// in the connection string). If EITHER of these options are turned off,
!the
!/// program successfully completes all 500 iterations. Otherwise, the error
!will occur
!/// at the start of iteration #100.
!///
!/// Tested using SQL Server 2000 SP3, Visual Studio .NET 2003, and
!/// the .NET Framework version 1.1. The problem originally appeared prior
to
!/// installing SQL Server SP3, so other combinations may also be a problem.
!///////////////////////////////////////////////////////////////////////////
/
!/
!using System;
!using System.Data;
!using System.Data.SqlClient;
!
!namespace SqlDebuggingTest2
!{
! /// <summary>
! /// Summary description for Class1.
! /// </summary>
! class Class1
! {
! /// <summary>
! /// The main entry point for the application.
! /// </summary>
! [STAThread]
! static void Main(string[] args)
! {
! try
! {
! for (int i = 0 ; i < 500; i++)
! {
! Console.Out.WriteLine("Iteration # {0}", i);
! SqlConnection conn = new
!SqlConnection("pooling=true;Server='(local)';Integrated
!Security=true;Initial Catalog=northwind;Application Name=Testing;");
! try
! {
! conn.Open();
!
! SqlCommand cmdToExecute = new SqlCommand();
! try
! {
! cmdToExecute.CommandText = "CustOrdersOrders";
! cmdToExecute.CommandType = CommandType.StoredProcedure;
! SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);
! try
! {
! cmdToExecute.Connection = conn;
! string customerId = "QUICK";;
! cmdToExecute.Parameters.Add(new SqlParameter("@CustomerID",
!customerId));
!
! DataSet ds = new DataSet("foo");
! try
! {
! adapter.Fill(ds);
! }
! finally
! {
! if (ds != null)
! ds.Dispose();
! }
! }
! finally
! {
! if (adapter != null)
! adapter.Dispose();
! }
! }
! finally
! {
! if (cmdToExecute != null)
! cmdToExecute.Dispose();
! }
! }
! finally
! {
! if (conn != null)
! {
! conn.Close();
! conn.Dispose();
! }
! }
! }
! }
! catch (Exception ex)
! {
! Console.WriteLine("{0}", ex.ToString());
! Console.WriteLine("Program terminated."); // line exists to set
!breakpoint on.
! }
!
! }
! }
!}
!
!
!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top