Using 1.0.48.0, I'm basically doing what Stevie77 is doing: filling a database table with data. And I'm getting this error with every run - sometimes after a few minutes and sometimes after half an hour!
Having set breakpoints in the code whereever SQLITE_CANTOPEN is returned, I've found this error to occur when SQLite needs to create the journal file. The breakpoint hit is in os_win.c:1151.
Callstack is:
SQLite.Interop.DLL!winOpen(sqlite3_vfs * pVfs=0x00000000, const char * zName=0x046435e4, sqlite3_file * id=0x04643560, int flags=2069, int * pOutFlags=0x00000000) Line 1151 C
> SQLite.Interop.DLL!winOpen(sqlite3_vfs * pVfs=0x10071788, const char * zName=0x046435e4, sqlite3_file * id=0x04643560, int flags=2070, int * pOutFlags=0x00000000) Line 1149 + 0x1d bytes C
SQLite.Interop.DLL!sqlite3OsOpen(sqlite3_vfs * pVfs=0x10071788, const char * zPath=0x046435e4, sqlite3_file * pFile=0x04643560, int flags=2070, int * pFlagsOut=0x00000000) Line 134 + 0x1c bytes C
SQLite.Interop.DLL!pager_open_journal(Pager * pPager=0x04643458) Line 3566 + 0x1d bytes C
SQLite.Interop.DLL!sqlite3PagerBegin(PgHdr * pPg=0x0464aef8, int exFlag=0) Line 3661 + 0x9 bytes C
SQLite.Interop.DLL!sqlite3BtreeBeginTrans(Btree * p=0x04643208, int wrflag=1) Line 1862 + 0x19 bytes C
SQLite.Interop.DLL!sqlite3VdbeExec(Vdbe * p=0x08b8bd98) Line 2534 + 0x13 bytes C
SQLite.Interop.DLL!sqlite3Step(Vdbe * p=0x08b8bd98) Line 330 + 0x9 bytes C
SQLite.Interop.DLL!sqlite3_step(sqlite3_stmt * pStmt=0x08b8bd98) Line 397 + 0x9 bytes C
SQLite.Interop.DLL!sqlite3_step_interop(sqlite3_stmt * stmt=0x08b8bd98) Line 454 + 0x9 bytes C
[External Code]
System.Data.SQLite.dll!System.Data.SQLite.SQLite3.Step(System.Data.SQLite.SQLiteStatement stmt = {System.Data.SQLite.SQLiteStatement}) Line 121 + 0x13 bytes C#
System.Data.SQLite.dll!System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() Line 571 + 0x16 bytes C#
<snip...>
Added a breakpoint where winOpen is called from winOpen (oswin.c:1149), and had another go.
This time, hitting the breakpoint at 1149, I found the last error to be 5:Access is denied.
Just for the fun of it, I did another execution of CreateFileW. This time it succeded.
So, the $10000 question is: why the occationally 'access denied error'?
I'm running the app using the default data directory, i.e. where the exe resides
Any clues, anyone?
Be the way, if you wonder... 'os_win.c.... that's not included in the 1.0.48.0 sources'... you are right. Apparently, one is not allowed to set breakpoints in a source file being included by another source file. That's exactly the case with the amalgamation source (stupid debugger), so I had to bring in and compile the complete SQLite source tree. I found it necessary to move some structs from c to h, because otherwise crypt.c could not find them.
I think it would be a clever approach to switch over to compile the source tree instead of the amalgamation, allowing for deep debugging.