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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:01:25+00:00 2026-05-12T23:01:25+00:00

This is a relatively simple question but I want to make sure I am

  • 0

This is a relatively simple question but I want to make sure I am doing this the right way.

What is the best practice for connecting to a database? This is how I am currently doing it and I want to make sure this is more or less following best practice.

private static SQLiteConnection conn;

    public static SQLiteConnection Conn
    {
        get 
        {
            try
            { 
                if (conn == null)
                    conn = new SQLiteConnection(fullName);

                if (conn.State != ConnectionState.Open)
                {
                    conn.ConnectionString = connectionString;
                    conn.Open();
                }
            }
            catch (Exception Excp)
            {
                DataErrorLogger.WriteError(Excp, "");
            }

            return conn;
        }

    }

When I actually use the connection I am doing this.

 using (SQLiteConnection conn = new SQLiteConnection(SQLiteConn.Conn))
        {}

Thanks!

  • 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-12T23:01:25+00:00Added an answer on May 12, 2026 at 11:01 pm

    There are many ways to connect to databases in .NET. You’ve of course found one of them and it will work just fine.

    There are three main schools of thought that I’ve seen 1st hand and really experienced regarding .NET data connections:

    1. The first is a more “wizardy” approach to coding that involves adding a connection object to your form, and then using the table bindings and such to “wizard” your form into submission. This is generally efficient on the client machine since .NET pre-optimizes a lot of it if its done through its binding and wizard functions. However, depending on what you are doing it could introduce a bit more network traffic. Also, sometimes the wizards do not do exactly what you want, and relying on wizards can sometimes introduce hours of googling to figure out why the wizard isn’t doing what you want it to.

    2. The second (and my preferred way) is writing back-end code to pull down datasets and then display them in your software. This is I believe what your posted code is doing. I believe that it gives you the best flexibility with the data while still allowing you to do some binding and wizardy coding. This is usually less efficient on the client than option 1 since DataSets can be passed byVal on accident sometimes and cannot be quite as pre-optimized as the wizardy approach can. It generally means less network traffic though because your queries will be more subsinct and in theory should be called less often because you can call the data out, store it, and reuse it elsewhere. Also, there is something to be said about the speed at which you can code in this manner as well. I also find it easier if you don’t know much about SQL string formatting and the like (which may be why we use this in the office for some of the other guys). Also, datasets require disposing so that they will be removed from memory.

    3. The third method for data connection that I’ve seen was an entire class built around reading in datarows from a datareader object. Upon doing some research on datareaders vs dataConnections and datasets, I’ve discovered that the datareader approach can be up to 10 times faster than datarow connections and they use far less memory and resources. You can also choose to truncate your result set by just not reading in more rows if you’ve gotten enough data or found what you were after (which should be done with a “TOP” or “WHERE” clause anyway). However, the drawbacks are the following:

      • Harder to code since you will have arrays of datarows instead of neat datasets
      • Cannot use wizards for the most part (some still compatible with datarow arrays)
      • I think it would be safe to say most beginning coders would look at it and say “wtf happened here?”
      • More network traffic.
      • Sequential access only.

    These are simply my observations. I would research any of the methods before choosing one of these. Also don’t forget about things like cacheing to prevent round trips to the server as much as possible, but make sure not to cache anything that will change while the program is running (from an external source). Don’t forget about multithreading and connection pools and the like. They are all very important features to keep in mind for any data access class.

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

Sidebar

Related Questions

I'm sure this is a relatively simple question, and there must be a good
I feel like this is a simple question, but I am still relatively new
I think that this is a relatively simple question. I just want to know
This is probably a relatively simple oversight, but I can't work out if I'm
I just cannot figure this out, it looks really simple but I'm relatively new
The question probably sounds a little odd, but the actual task is relatively simple,
I have what i thought was a relatively simple question but i cannot find
this question should be relatively simple and shouldnt even require much explanation i dont
This is a relatively simple question: I can trim a text with ellipsis using
Unfortunately, the answer to this question isn't quite as simple as it sounds... but

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.