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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:40:19+00:00 2026-05-25T16:40:19+00:00

I have a C# application that has been running just fine for the past

  • 0

I have a C# application that has been running just fine for the past year. However, in the past couple of months we have added more clients and the database has been reporting connection errors on a more consistent basis. It might be time to revisit the way connections are handled and perhaps there is a better way to do this. Here is the class that manages my connections:

public class myDAL
    {
        protected SqlConnection sqlConnection = new SqlConnection();

        protected void openConnection(string connection)
        {
                sqlConnection.ConnectionString = connection;
                sqlConnection.Open();            
        }


        protected void closeConnection()
        {            
            sqlConnection.Close();
        }

}

Note that I’m really doing nothing special to manage the connection. I just call the open and close as needed and this is happening from multiple clients at the same time. Am I doing anything obviously wrong here?

  • 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-25T16:40:20+00:00Added an answer on May 25, 2026 at 4:40 pm

    Jim your practice of having open and close connection methods inside another class is very old, modern .NET development follows a patter like this nowadays:

    using (SqlConnection conn = new SqlConnection("connection string here"))
    using (SqlCommand cmd = new SqlCommand("sql query", conn))
    {
        // execute it blah blah
    }
    

    see here: Closing SqlConnection and SqlCommand c# or search in SO for hundreds of questions and answers all telling the same, close the connection immediately either with a using like in this example or with a try/finally inside the same method, no need for one method to open and on method to close it, just prone to errors if anything happens in the between.

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

Sidebar

Related Questions

I have a web application that has been running just fine in Internet Explorer
I have an application that has been running fine since its launch over a
I have a 3.1 xcode project that has been running my app just fine
I have a c# .NET 2.0 application that has been running on W2K/IIS5 quite
I have an application that runs in fullscreen mode and has been working fine.
Background: We have an application that has been in the works for over a
I have an mvc application that has been coded to use Windows authentication and
I have a code base that has been used as an ASP.Net web application.
We have an application that has one or more text console windows that all
We have an ASP.NET 3.5 application that has been in production for over a

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.