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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T16:44:36+00:00 2026-05-28T16:44:36+00:00

I have client-server application, where server side is Azure WCF service with data in

  • 0

I have client-server application, where server side is Azure WCF service with data in SQL azure database. Clients are Windows Phone 7 silverlight applications. Client and server communicate throught WCF. Server is providing data to client which are stored in Azure SQL database.

I recently ran to some problems with pooling. I was creating new object every time when client request arrived. I was not closing this connections and very soon encountered exception:

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.

My question is – how should connection object to DB be handled? Should i create one connection object for every client request or should i create singleton object which should handle all calls to db? IS it even possible – does not connection object time out after some time or something?

I am using SQLConnection object:

private static SqlConnection connection
        {
            get
            {
                SqlConnectionStringBuilder connectionStringBuilder = new SqlConnectionStringBuilder
                {
                    DataSource = DB_SOURCE,
                    InitialCatalog = DB_NAME,
                    Encrypt = false,
                    TrustServerCertificate = false,
                    UserID = DB_USER,
                    Password = DB_PASS,
                };
                SqlConnection c = new SqlConnection(connectionStringBuilder.ToString());
                c.Open();
                return c;
            }
        }

        public static void execute(String query)
        {
            try
            {
                SqlCommand com = new SqlCommand(query, connection);
                com.ExecuteNonQuery();
            }
            finally
            {
                connection.Close();
            }
        }
  • 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-28T16:44:38+00:00Added an answer on May 28, 2026 at 4:44 pm

    I agree with the answers provided by Wiktor Zychla, Tobias, and Herve Roggero. They explain that:

    1. Your getter (connect property), doesn’t return the original SqlConnection that you were expecting, hence the original connection is not getting closed.
    2. You should create SqlConnections when you need them, keep them open only as long as you need them, and close them when you are done.

    Here’s a complete solution:

    private static string _connectionString = string.Empty;
    
    private static string connectionString
    {
      get
      {
        if (string.IsNullOrEmpty(_connectionString))
        {
          _connectionString = new SqlConnectionStringBuilder
          {
            DataSource = DB_SOURCE,
            InitialCatalog = DB_NAME,
            Encrypt = false,
            TrustServerCertificate = false,
            UserID = DB_USER,
            Password = DB_PASS,
          }.ToString();
        }
    
        return _connectionString;
      }
    }
    
    public static void Execute(String query)
    {
      using (SqlConnection connection = new SqlConnection(connectionString))
      using (SqlCommand command = new SqlCommand(query, connection))
      {
        connection.Open();
        command.ExecuteNonQuery();
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Silverlight application on the client communicating with the server side through
I have a client/server application that depends on MS SQL database for backend storage,
I have a client/server application that communicates with .Net remoting. I need my clients
I have a client-server application that uses .net remoting. The clients are in a
I have a client/server application. One of the clients is a CLI. The CLI
I have a client server application with multi-threading. The server side is failing with
i have a client & server application which communicate using WCF. To add some
we have a java server-client application with an applet in the client side. our
I have a client server based windows forms application that needs an administrator only
We have a client and server application currently testing on the same Windows 7

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.