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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:12:53+00:00 2026-05-23T12:12:53+00:00

Background info: I’m coding with C#, using Microsoft SQL Server for databases. I didn’t

  • 0

Background info: I’m coding with C#, using Microsoft SQL Server for databases.

I didn’t find much on Google on the subject, so I’m asking here: should I always close a connection to my database after performing a query?

I’m torn between two solutions (maybe better ones exist…):

  • either open the connection before querying, then close it right after the SQL query

  • or open the connection at the start of my application, and before each SQL query check if the connection is still up and reopen it if needed.

In the past, I used the first solution but I discovered that opening a new connection can take quite some time (especially over a VPN connection to my LAN opened through 3G), and that it would slow down my application. That’s why I decided to go with the second solution (in that case, my connection should be always up if we forget about time-out) and noticed some better performances.

Do I need to close the connection at the end of my application or can I forget about it?

  • 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-23T12:12:54+00:00Added an answer on May 23, 2026 at 12:12 pm

    Yes, you should close your connection after each SQL query. The database connection pool will handle the physical network connection, and keep it open for you. You say that you found that opening a connection can take some time – did you find that the application was really doing that multiple times?

    (I hope your real application won’t be talking directly to the database over 3G, btw… presumably this is just for development purposes…)

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

Sidebar

Related Questions

Please help! Background info I have a WPF application which accesses a SQL Server
Background-info: I'm using Microsoft Visual Web Developer 2010 Express. Info about my (lack of)
Background info : I was handed a Tool, which was made using MS-Access 2007,
Some background info; LanguageResource is the base class LanguageTranslatorResource and LanguageEditorResource inherit from LanguageResource
Background: At my company we are developing a bunch applications that are using the
Background I am writing and using a very simple CGI-based (Perl) content management tool
Background Info I am working on setting up a method for my company's developers
Background Info: File Replication is Lame Currently, we have a massive, high-traffic ASP.NET web
Background info: I've set up a very simple .NET solution in VS2008 that contains
BACKGROUND INFO: I need to update some data from the web, about every hour

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.