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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:31:23+00:00 2026-06-03T08:31:23+00:00

I am creating desktop application in winform that will use Sqlite Database. So I

  • 0

I am creating desktop application in winform that will use Sqlite Database.

So I created Sqlite Helper class that uses System.Data.SQLite and each method of that Helper class opens and closes connection.

But now I also added ability to attach additional databases but after Connection is Closed, all attached databases gets lost.

To correct this I modified the class so that the connection is opened in constructor and remains open.

After the application ends, I want that connection to close without explicitly calling the Close method.

Any suggestions how to do that?

  • 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-06-03T08:31:24+00:00Added an answer on June 3, 2026 at 8:31 am

    Keeping the connection open for the lifetime of your application is not a good way to go.
    I suggest to not follow this route.
    On the contrary, I will try to encapsulate the functionality to attach a database inside a method that could be called on the need to use basis.

    For example:

    private static void AttachDB(string fileDB, string aliasName, SQLiteConnection cn) 
    { 
        string sqlText = string.Format("ATTACH '{0}' AS {1}", fileDB, aliasName) 
        SQLiteCommand cmd = new SQLiteCommand(sqlText, cn) 
        cmd.ExecuteNonQuery(); 
    } 
    

    then in your code

    using(SQLiteConnection cn = new SQLiteConnection(GetConnectionString()))
    {
         AttachDB(@"C:\SQLite\UserData.sqlite3", "UserData", cn);
         // Do your code here
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a desktop/client application that will be installed on +/- 5 PCs,
I'm developing a desktop application. For that I'm creating class libraries. At the development
I'm creating a desktop application using Visual studio and C# that uses MySQL. I
We're creating a desktop application which will use OLAP server to perform analysis. I'm
I'm creating a java desktop application that draws a map in a JFrame designing
I am creating a desktop application that stores rich text documents to a SQL
I'm creating a WPF (in c#) application that will create html files based on
I am creating a NSIS installer for a desktop application. I am making use
I'm developing a new desktop application that will have several views such as a
I am currently working on a c# .NET desktop application that will be communicating

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.