You receive a "Timeout expired" error message when you run a Visual Studio .NET 2003 application

Symptoms

When you enable the SQL Server debugging feature in Microsoft Visual Studio .NET 2003, and then you run an application, you receive the following error message:
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.

Cause

The SQLClient Pool runs out of
SqlInternalConnection objects.

Workaround

To work around this problem, use one of the following methods:

Method 1

Change your project configuration to Release mode. To do this, follow these steps:
  1. In Visual Studio .NET, click Configuration Manager on the Build menu, and then click Release in the Active Solution Configuration list.
  2. On the Debug menu, click
    Start to run your application. Notice that you do not receive the error message that is mentioned in the "Symptoms" section.

Method 2

Change the Debug mode configuration properties of your project. To do this, follow these steps:
  1. In Visual Studio .NET, right-click your application in Solution Explorer, and then click Properties.
  2. In a Microsoft Visual Basic .NET project, click Debug under Configuration Properties, and then clear SQL Server debugging under
    Enable Debuggers.

    In a Microsoft Visual C# .NET project, click
    Debugging under Configuration Properties, and then set the value of Enable SQL Debugging under
    Debuggers to False.

Status

This behavior is by design.

More Information

  1. Start Visual Studio .NET 2003.
  2. On the File menu, point to New, and then click Project.
  3. Click Visual Basic Projects or Visual C# Projects under Project Types, and then click Windows Application under Templates.
  4. Name the project
    SampleApplication. By default, Form1 is created.
  5. Add a button control to Form1.
  6. Double-click the button that you added to Form1.
  7. Add the following code at the top of the Form1class:

    Visual Basic .NET

    Imports System
    Imports System.Data.SqlClient

    Visual C# .NET

    using System;
    using System.Data.SqlClient;
    using System.Diagnostics;
    using System.Windows.Forms;
  8. In Visual Basic .NET, add the following code to the Click event of the Button1 button:
    Dim iCount As Integer = 1
    Try
    Do
    Dim sqlConn As New _
    SqlConnection("Data Source=localhost;trusted_Connection=yes;initial catalog = Northwind")
    sqlConn.Open()
    Trace.WriteLine("opening connection " & CStr(iCount))
    sqlConn.Close()
    Trace.WriteLine("closing connection " & CStr(iCount))
    sqlConn.Dispose()
    Trace.WriteLine("disposing connection " & CStr(iCount))
    iCount = iCount + 1
    Loop Until iCount > 200
    Catch ex As Exception
    Trace.WriteLine(ex.ToString)
    End Try
    In Visual C# .NET, add the following code to the Clickevent of the button1 button:
    int iCount = 1;
    try{
    while (iCount <= 200){
    SqlConnection sqlConn = new SqlConnection("Data Source=localhost;" +
    "trusted_Connection=yes;initial catalog = Northwind");
    sqlConn.Open();
    Trace.WriteLine("opening connection " + iCount.ToString());
    sqlConn.Close();
    Trace.WriteLine("closing connection " + iCount.ToString());
    sqlConn.Dispose();
    Trace.WriteLine("disposing connection " + iCount.ToString());
    iCount = iCount + 1;
    }
    }catch(Exception ex){
    Trace.WriteLine(ex.Message);
    }
  9. On the Build menu, click Configuration Manager, and then click Debug in the Active Solution Configuration list.
  10. In Solution Explorer, right-click
    SampleApplication, and then click
    Properties.
  11. In a Visual Basic .NET project, click Debug under Configuration Properties, and then click to select SQL Server debugging under
    Enable Debuggers.

    In a Visual C# .NET project, click
    Debugging under Configuration Properties, and then set the value of Enable SQL Debugging under
    Debuggers to True.
  12. Click OK to close the
    SampleApplication Property Pages dialog box.
  13. On the Debug menu, click
    Start to run your application.

References

For more information about pooling in MDAC, visit the following Microsoft Developer Network (MSDN) Web site:
Propriedades

ID do Artigo: 830118 - Última Revisão: 23 de mar de 2009 - Revisão: 1

Comentários