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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:02:45+00:00 2026-05-31T15:02:45+00:00

I have a client Server app that uses .NET Remoting. I have a helper

  • 0

I have a client Server app that uses .NET Remoting.
I have a helper class on the server portion of my app DBQuery.
DBQuery holds the DatabaseConnection, and the SQLCommand object, Commander and performs the queries passed to it.

Each time a query is performed, it verifies that the Commander has an open connection.
(it recreates the Commander if necessary.)

Considering it only connects to one Database, should I make my DBConnection static?
(DBConnection creates the commander, DBConnection.CreateCommand())

current properties defined below:

/// <summary> connection used for querying with </summary>
public DBConn DBConnection 
{ get { return _conn ?? (_conn = new DBConn()); } }

/// <summary> Command object for processing the queries </summary>
private SqlCommand Commander
{
    get
    { 
      return _commander ??  
            (_commander = DBConnection.Connection.CreateCommand());
    }
}

DBConn – wraps SqlConnection and supplies the appropriate connection information from app.config

  • 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-31T15:02:46+00:00Added an answer on May 31, 2026 at 3:02 pm

    Even if it’s static, never use a single connection – for one thing I don’t believe the connection is thread-safe, so it won’t necessarily take kindly to being called in parallel from two different clients.

    Even if I’m wrong about that (and if I am, I still wouldn’t share one connection between multiple threads), but if something happens with the database server, let’s say it gets restarted or the service itself does (due to an upgrade released by your support team) then the connection will be dropped and you have no way of re-opening it again – your service/app has to be restarted. Chances are that it’ll actually end up throwing an exception the next time you try and do something with it.

    Also, where do you dispose the connection? It’s very difficult to dispose of a static object unless you do the work to hook into a shutdown event, which isn’t always reliable. Relying on an AppDomain’s shutdown to dispose of things for you just isn’t good practise.

    Create a connection when you need it and dispose of it when you’re done with it. Based on the code you’ve given, in simplest terms:

    using(var conn = new DbConn().Connection)
    {
      SqlCommand command = conn.CreateCommand();
      /* query and get results here */
    }
    

    Although in reality you might want to make you DbConn class IDisposable and chain to the underlying Connection‘s Dispose method in it’s implementation of IDisposable.Dispose – that way you can do

    using(var dbconn = new DbConn())
    {
      //now you can use dbconn.Connection knowing that it will be disposed of
    }
    

    Note – the using block will still work if the new DbConn() is replaced with a factory method or property get – it just ensures that Dispose() is called on the object when then block exits, and even if an exception occurs.

    By doing this, you get around all the problems I highlight in the first half of my answer.

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

Sidebar

Related Questions

We have a huge client/server WinForms app that uses .NET remoting to pass DAOs
I have an ASP.NET MVC server app and client code which uses jquery. I'd
I have a client/server app. The server component runs, uses WCF in a 'remoting'
I`m writing client-server app for windows using WinSock and I have class for server.
I have an app that communicates with a server that uses HTTP Digest authentication.
I have a simple ASP.NET web app which uses a WCF Client to talk
I’m doing maintenance on an asp.net web app that uses remoting to call a
I am developing a client server app that uses ssl (openssl) to establish a
I have a C++ client app that uses Boost ASIO to make SSL connections
I've got a small client/server test application where I have a Flex app that

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.