Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL logic error or missing database no such table

Tags:

c#

sqlite

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();
}
like image 706
Jetpack Avatar asked Mar 25 '15 08:03

Jetpack


2 Answers

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

like image 197
Jetpack Avatar answered Oct 27 '22 05:10

Jetpack


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

like image 38
Cristina Alboni Avatar answered Oct 27 '22 05:10

Cristina Alboni