1

I have small test Sqlite database on my Raspberry Pi2.

Connection string is:

con = new SqliteConnection("Data Source=test.db,version3");

If I want fetch data, I use:

cmd = new SqliteCommand("SELECT * FROM users",con);
reader = cmd.ExecuteReader();
while(reader.Read()){ 
.... 
}

I get this Exception:

Mono.Data.Sqlite.SqliteException: SQLite error
no such table: users
at Mono.Data.Sqlite.SQLite3.Prepare (Mono.Data.Sqlite.SqliteConnection cnn,
System.String strSql, Mono.Data.Sqlite.SqliteStatement previous,
UInt32 timeoutMS, System.String& strRemain) [0x00000] in <filename unknown>:0
at Mono.Data.Sqlite.SqliteCommand.BuildNextCommand () [0x00000] in <filename unknown>:0

I'll grateful for whatever advice.

skybedy
  • 33
  • 8

2 Answers2

0

The problem is in your connection string, it should be like this: "Data Source={path-to-your-database-file}test.db;Version=3;"

mnwsmit
  • 1,198
  • 2
  • 15
  • 31
  • Table users certainly exists, because If I try this through console: `sqllite3 test.db;` and `SELECT * FROM users;` - it works. – skybedy Mar 08 '16 at 08:59
  • @skybedy changed my answer – mnwsmit Mar 08 '16 at 09:19
  • I tried `con = new SqliteConnection("Data Source=test.db;Version=3;")` , however without success. – skybedy Mar 08 '16 at 09:28
  • Is the test.db at the location where it is expected by SQLite? I highly suspect it now looks at the wrong location (e.g. location of executing assembly). See this SO answer for some inspiration: http://stackoverflow.com/a/5003238/3997704 – mnwsmit Mar 08 '16 at 09:45
  • Bingo. Thank you very much. I wrote "Data Source=/home/pi/test.db,version3" and seems, that it works fine. – skybedy Mar 08 '16 at 11:52
  • Great to hear! Accept answer? – mnwsmit Mar 08 '16 at 11:58
0

A database file with the name test.db,version3 does not yet exist, so it is created.

Connection string parameters always must use an equals sign: Version=3.

CL.
  • 173,858
  • 17
  • 217
  • 259