1

As shown in pictures, "ProjectDB.db" is a database I built through the SQLite Compact Toolbox. The database indeed exists in that folder path. The exception as in the title is thrown as I debug the app.

UWP App. Visual Studio 2017. Windows 10.

Snapshot of Errors while running application

enter image description here

enter image description here

Connection string for connecting SQL lite Database

SQLiteConnection db = 
new SQLiteConnection(@"Data Source=C:\Users\georg\source\repos\DatabasePractice\ProjectDB.db;Version=3;";
db.Open();
Saineshwar Bageri - MVP
  • 3,851
  • 7
  • 41
  • 47
George Feng
  • 49
  • 1
  • 9
  • What is the inner exception? – Bassem Jan 28 '18 at 08:37
  • What is an inner exception and how to see it? – George Feng Jan 28 '18 at 19:25
  • 1
    When the exception is thrown, click on the red X icon, then click on View Details, expand the inner exception node and find the message within it. The inner exception of an exception, sometimes, helps you to dig deeper and find the cause behind that exception. – Bassem Jan 29 '18 at 05:37

2 Answers2

2

Sqlite on Windows a directory/path should use a double backslash like this:

C:\\Users\\georg\\source

If this does not solve your problem, attempt these troubleshooting steps:

  1. Is the Database stored on a remote server or 'read-only' directory?
  2. Is the parent directory a 'read-only' directory?
  3. Try executing your code with the Source="...Practice\ProjectDB;" not "\ProjectDB.db;"
  4. Is something else attempting to read the database? Although this should throw a 'database locked' exception which makes this one unlikely.
Owen Easter
  • 248
  • 2
  • 10
  • 1
    I appreciate your advice. But the exception is still thrown after I make the directory readable, and even if I move the database file to another disk. This is really making me frustrated... – George Feng Jan 28 '18 at 19:32
  • 1
    Can you open the database with sqlite database browser? – Owen Easter Jan 28 '18 at 23:41
0

I was facing same issue on the shared hosting server, My C# code was able to read data from SQLIte db file. But while add / update data it was throwing Error "unable to open database"

I tried many options suggested on stackoverflow But after referring https://stackoverflow.com/a/17780808/2021073 and https://www.sqlite.org/pragma.html#pragma_journal_mode I tried adding journal mode=Off; to the Connection string

and it worked for me

sample code

SQLiteConnection connection = new SQLiteConnection("Data Source=G:\dbfolder\sqlite3.db;Version=3;Mode=ReadWrite;journal mode=Off;", true);
Alvin
  • 11
  • 4