views:

150

answers:

2
SQLiteConnection conn = new SQLiteConnection("Data Source=/data/bakkal.db3;");
conn.Open();
conn.Close();

I am new at programming so maybe the problem is a very dumb one, sorry for that. I am trying to connect my project with a database which exists in the directory listed above. But the project gives an error at "conn.Open();" line which is just "unable to connect database". Database has no passwords or etc, it is just a very small database with 2 columns.

I don't think it is going to change anything but my project is a WPF application project, maybe differs.

Thanks for any help

A: 

If the database file is located in the same folder as the executable you could try this:

using (var conn = new SQLiteConnection(@"Data Source=|DataDirectory|bakkal.db3"))
{
    conn.Open();
}

If it is in a subfolder:

@"|DataDirectory|data\bakkal.db3"

If not use absolute path:

@"c:\somepath\data\bakkal.db3"
Darin Dimitrov
A: 

Write out the location of the database completely [drive][path][databasefile]

using (SQLiteConnection connection = new SQLiteConnection(@"Data Source=c:\data\bakkal.db3"))
{
    connection .Open();
}
Willem van Rumpt