Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to connect my sqlite databse by my visual studio 2013 it is showing error
while database file already added in my bin folder

What I have tried:

public void connect()
       {
           SQLiteConnection sqlite_conn=new SQLiteConnection();
           SQLiteCommand sqlite_cmd = new SQLiteCommand();
           SQLiteDataReader sqlite_datareader;
           string connstr = "Data Source=dbVkcaddin.db;Version=3;New=False;Compress=True;";
           sqlite_conn.ConnectionString = connstr;
           sqlite_conn.Open();
           sqlite_cmd.CommandText = "SELECT * FROM Client_contact";
           sqlite_cmd.Connection = sqlite_conn;
           sqlite_datareader = sqlite_cmd.ExecuteReader();
           while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
           {
               string myreader = sqlite_datareader.GetString(0);
               MessageBox.Show(myreader);
           }
           // We are ready, now lets cleanup and close our connection:
           sqlite_conn.Close();
       }
Posted
Updated 9-Dec-17 0:35am
Comments
Richard MacCutchan 9-Dec-17 5:54am    
What error, where does it occur?
Member 12088223 10-Dec-17 8:08am    
Add the sqlite Database to some path for example C:\\Users\\data\\test.db and use following code,

public void connect()
{
SQLiteConnection sqlite_conn=new SQLiteConnection();
SQLiteCommand sqlite_cmd = new SQLiteCommand();
SQLiteDataReader sqlite_datareader;
//string connstr = "Data Source=dbVkcaddin.db;Version=3;New=False;Compress=True;";
//sqlite_conn.ConnectionString = connstr;
string fullPath = "C:\\Users\\data\\test.db";
SQLiteConnection conread = new SQLiteConnection("Data Source=" + fullPath);
sqlite_conn.Open();
sqlite_cmd.CommandText = "SELECT * FROM Client_contact";
sqlite_cmd.Connection = sqlite_conn;
sqlite_datareader = sqlite_cmd.ExecuteReader();
while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
{
string myreader = sqlite_datareader.GetString(0);
MessageBox.Show(myreader);
}
// We are ready, now lets cleanup and close our connection:
sqlite_conn.Close();
}

1 solution

The problem is probably that it can't find the database file, as the error message suggests - and that's probably because of where you have put it.

The "bin" folder is a bad idea - your app does not run in it in the debugger *it runs in "bin/debug", so it won't get found, and in production it will also fail because the app will be in a read-only part of the file system - "Program Files"

Move the DB to a more sensible place - Where should I store my data?[^] should help - and your problem will likely disappear.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900