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 7635693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:29:26+00:00 2026-05-31T07:29:26+00:00

In my Windows application I try to connect to SQL Server 2008 with following

  • 0

In my Windows application I try to connect to SQL Server 2008 with following code:

SqlConnection connection = new SqlConnection(Properties.Settings.Default.KargarBandarConnectionString);
SqlCommand command = new SqlCommand("Select IsAdmin from Users where UserName=@UserName And Password=@Password", connection);
SqlDataReader dataReader = null;

command.Parameters.AddWithValue("@UserName", UserNameTextBox.Text.Trim());
command.Parameters.AddWithValue("@Password", PasswordTextBox.Text);
try
{
    connection.Open();
    dataReader = command.ExecuteReader();

    if (dataReader.HasRows)
    {
        while (dataReader.Read())
        {
            IsAdmin = dataReader.GetBoolean(0);
        }
        this.DialogResult = DialogResult.OK;
    }
    else
    {
       FMessageBox.ShowWarning("error");
        UserNameTextBox.Focus();
    }
}
catch (Exception ex)
{
    if (progressForm != null)
        progressForm.Close();

    FMessageBox.ShowError(ex.Message);
}
finally
{
    if (dataReader != null)
    {
        dataReader.Close();
        dataReader.Dispose();
    }
    if (connection != null)
    {
        connection.Close();
        connection.Dispose();
    }
}

Everything works properly, but sometimes I get the following error:

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

How can this be solved?

  • 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-31T07:29:27+00:00Added an answer on May 31, 2026 at 7:29 am

    The reason you’re getting this exception is because you have exhausted your connection pool and the number of “available” connections in your application.

    Every time you open a connection, one is pulled from the connection pool if possible, or a new one is created if not.

    However, to prevent galloping usage of connections, a limit of 100 (I think this is configurable) exists, and if you try to use more than 100 simultaneous connections, the code will not create new ones, and instead sit down to wait for one to be returned to the pool, and in this case you get a timeout if it sits too long.

    So, for the particular example of code you’ve shown, I would:

    Close the connection before I show an error messages to the user

    However, unless 100 users are seeing the error message and leaving it there at the same time, it is unlikely the code you’ve shown is the cause of this problem.

    Other than that, I would go through the entire application and ensure you don’t have any connection leaks other places.

    This particular type of exception can occur in one spot even though the problem is somewhere else. Example: A report is leaking an open connection every time it runs, and you run it 100 times successfully, then someone tries to log in, and the exception occurs in the login form.

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

Sidebar

Related Questions

I am new to sql server express and i installed sql server express 2008
I'm working on a C# application that queries a SQL Server 2008 Express instance
I run Visual C++ Windows Forms application and MS SQL server 2005. I succeeded
Some background: we have a windows application (c#) that locate in the system try.
I try to add an addons system to my Windows.Net application using Reflection; but
I try to create an Application on Windows 8 with VS 11 with C#,
I have a database called MyDB in a Microsoft SQL Server 2008 Express instance
When I try to connect to a MySQL Database from my .NET application i
I have an SQL 2008 server running three instances. Each instance is assigned a
I am trying to connect to an mdf file using the following connection string:

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.