12

I am trying to read all data from the table Condition in a local sqlite database. However I am getting this error:

SQL logic error or missing database no such table

The database is located in the same directory as the file that's calling it.

This is my code:

SQLiteConnection m_dbConnection = new SQLiteConnection("Data Source=myDatabase.sqlite;Version=3;");
m_dbConnection.Open();

try
{
    string sql = "select * from Condition";
    SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);

    SQLiteDataReader reader = command.ExecuteReader();

    while (reader.Read())
        Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["id"]);

    Console.ReadLine();
    return null;
}
catch (Exception exc)
{
    return null;
}
finally
{
    m_dbConnection.Close();
}
2
  • Is that the exact path your using for the database file? Commented Mar 25, 2015 at 8:12
  • 2
    I would suggest you try a fully qualified path for your datasource (like 'C:/whatever/myDatabase.sqlite' to check if your code actually finds the database file. Your statement "same directory as the file that is calling it" sounds suspicious to me - how are you running your code? Commented Mar 25, 2015 at 8:18

3 Answers 3

14

I have fixed the issue by using a absolute path instead of a relative path. thanks to Eternal21 https://stackoverflow.com/a/20083762/3483812

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

1 Comment

I was going to say in the comment above, as you run the program the directory becomes project/bin/debug, I'm guessing yours was in the directory with the solution file?
9

The database should be located in your bin folder, or else specify the absolute path to the .sqlite file.

Comments

0

I received the same error message on a linux system. When the database was created, the program was running as root: when the error occurred, the program was running as me. Basically, I didn't have write permission on the file.

Comments

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.