0

I have create Set up file for WPF application and the database is SQLite DB. After the installation the SQLite DB is located this path in C folder,

C:\Program Files (x86)\myCompany\myScanApp.

enter image description here

Then I have written connection string like this way for establishing a connection to SQLite DB,

static SQLiteConnection dbConnection = new SQLiteConnection(@"Data Source=C:\Program Files (x86)\myCompany\myScanApp\test.s3db;");

Then I have created a Setup file again and then run this application on another PC. But, it is failing to run in the PC. How can I access DB in application?

1
  • What does “failing to run” mean? It's throwing an exception? You need to tell us the exception. Also, `C:\Program Files (x86)` is typically not a place the user can or wants to change; if you expect users to change your database you should copy it to a place the user can change. Commented Aug 16, 2020 at 20:49

1 Answer 1

3
using(SQLiteConnection conn= new SQLiteConnection(@"Data Source=C:\Program Files (x86)\myCompany\myScanApp\test.s3db;"))
{
    conn.Open();

    SQLiteCommand command = new SQLiteCommand("Select * from yourTable", conn);
    SQLiteDataReader reader = command.ExecuteReader();

    while (reader.Read())
       Console.WriteLine(reader["YourColumn"]);

 
    reader.Close();
}

Something like this should work. Here whole article Getting started with SQLite in C#

Sign up to request clarification or add additional context in comments.

4 Comments

Hi I have also written this connection sting, but it caused error when I am trying to run applications after installation. How can I ?
@AbhilashJA Causing error doesn't mean anything to me. connectionstrings.com/sqlite here article about connection strings. Don't use static connection string also ! The whole code here is part of a Method.
Yes. Right... it's working. I did write connection string like this:- public SQLiteConnection dbConnection = new SQLiteConnection(@"Data Source=C:\Program Files (x86)\hedronix\qScan\test.s3db;"); Thanks.
@AbhilashJA okay if it is working make the answer correct

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.