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

  • SEARCH
  • Home
  • 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 6021159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:40:21+00:00 2026-05-23T03:40:21+00:00

Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool.

  • 0

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 is the first ASP.net site I developed a long time ago, it has this code at the top of a lot of pages (and in a lot of methods).

cn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToString());
cn.Open();

A lot of pages don’t have:

cn.Close();

Also none of the pages do using(SqlConnection...), (although all the data readers are in using blocks).

First question is, is the the primary candiate for the error?

Second question is, is the best way to solve this refactoring/manually searching for unclosed connections? I know it’s an ugly hack, but the time spent refactoring will be huge, but can we set a scheduled task to recycle the connection pool once a day at 3am or something?

  • 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-23T03:40:22+00:00Added an answer on May 23, 2026 at 3:40 am

    Yes, that is the primary cause of the error. Currently, many of those connections will wait until the next GC to re-pool the underlying connection. You will exhaust the pool (and database connections) pretty quickly.

    The best way of refactoring this is to add the missing using, such that the connection is scoped. Personally I’d also refactor that to a single method, i.e.

    using(var cn = SomeUtilityClass.GetOpenConnection())
    {...}
    

    Closing the reader does little unless the reader is marked to close the connection; and having the data-reader close the connection (via a behaviour) sort of works, but it assumes you get as far as consuming the reader – it won’t necessarily behave well in error scenarios.

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

Sidebar

Related Questions

I'm getting Timeout expired. The timeout period elapsed prior to obtaining a connection from
Message: Timeout expired. The timeout period elapsed prior to obtaining a connection from the
Timeout expired. The timeout period elapsed prior to completion of the operation or the
Error code: Timeout Expired. The timeout period elapsed prior to completion of the operation
I am getting this error on my website: Timeout expired. The timeout period elapsed
I got the error: error connecting: Timeout expired. The timeout period elapsed prior to
From time to time our server throw this well-known exception: Timeout expired. The timeout
We have been getting this Oracle connection pool exception a lot recently for our
Per this helpful article I have confirmed I have a connection pool leak in
I've got an asp.net 4 based web application with connection pool issues. Timeout expired.

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.