Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:18:05+00:00 2026-05-23T14:18:05+00:00

I have a problem in the code that I have written using .NET. The

  • 0

I have a problem in the code that I have written using .NET.

The problem is that somewhere I have some dodgy database code that means that after some time I get the following 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.

I know that it is because somewhere I haven’t disposed of one of my datareaders or something similar which means it still has the connection open so its not being returned to the pool. I’m having a bit of problem finding where this is happening in my code though.

So my question:

Is there any way to query the connection pool to find out what its in use connections are doing. I’m just looking for a way to find what query is being run to allow me to find the offending piece of code.

For what its worth I don’t have permissions to run an activity monitor on the database in question to find out that way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:18:05+00:00Added an answer on May 23, 2026 at 2:18 pm

    Is there any way to query the
    connection pool to find out what its
    in use connections are doing.

    No. Not really. The connection pool is something that your application maintains (actually a List<DbConnectionInternal> ) If you really wanted to you could get to the connections in the pool via reflection or if you are debugging, via a local or watch window (see below), but you can’t get to what’s happening on that connection from there or which object should have called Connection.Close (or Dispose). So that doesn’t help

    enter image description here

    If you’re lucky you can execute sp_who or sp_who2 at the moment you get the timeout when you’ve run out of pooled connections when but its highly likely that most of the results are going to look like this .

    SPID Staus    Login Hostname  Blkby DBname Command          ....
    ---- -------  ----- --------- ----- ------ ---------------- 
    79   sleeping uName WebServer .     YourDb AWAITING COMMAND .....
    80   sleeping uName WebServer .     YourDb AWAITING COMMAND .....
    81   sleeping uName WebServer .     YourDb AWAITING COMMAND .....
    82   sleeping uName WebServer .     YourDb AWAITING COMMAND .....
    

    Which means that yes indeed your application has opened a lot of connection and didn’t close them and isn’t even doing anything with them.

    The best way to combat this is to profile your application use the ADO.NET Performance Counters and keep a close eye on NumberOfReclaimedConnections and also do a thorough code review.

    If you’re really desperate you can Clear the pool when you encounter this problem.

    using (SqlConnection cnn = new SqlConnection("YourCnnString"))
    {
    
         try
         {
                cnn.Open();
         }
         catch (InvalidOperationException)
         {
                 SqlConnection.ClearPool(cnn);
         }
         cnn.Open();
    
    }
    

    I do however caution you against this because it has the potential of choking your DB server because it allows your application to open as many connections as the server will allow before it just runs out of resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an intermittent problem with some code that writes to a Windows Event
I have some code that I'd like to run on a page. My problem
I've written some tests for .net code that invokes calls to my SQL Server.
I have some VB.NET code that creates a TransactionScope instance: LoggingUtility.LogDebug(UpdateCallTable, SatComCallDataImporter, About to
I have written some simple code, to send en auto generated email, using the
I have a problem with a c# assembly (.net 2.0 written using Visual studio
I've got some (badly written) legacy code that I have to modify but I'm
I recently have a problem that my java code works perfectly ok on my
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml
I have a piece of software written in C#.NET that communicates with a device

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.