On 18 May 2011, at 9:09pm, Brancke, Brad wrote: > Once in a while when we power on the device and start my application, > this query fails: > > "SELECT storage_enum, mode, GPSDisplayDMS, UserRealID, UserEffID FROM > Settings;" > > with the reason "unable to open database file"
I assume that this is the first command you execute against the database after you _open() it. > I suspect something didn't get closed properly when the unit powered > off. > > Weird: > > 1. If I copy the db file to my PC, it opens and reads just fine. > > 2. If I just make a copy of it on the device itself (same folder > and everything), then I can query the *copy* of the file just fine. > > sqlite3_open() always succeeds and returns SQLITE_OK. The failure is > when sqlite3_exec() tries to run. Then we sqlite3_close() the db. The diagnostics you paste below that are really good. Thanks for posting them. The problem is unlikely to be about the contents of anything properly saved in the database file. I think it's more likely to be something about the file system (privileges, spare file handles, etc.). Can you check (by eye or write a small utility) whether any journal files are present in the directory of the database ? Perhaps you get the error when and only when the database wasn't closed properly. If any journal files (files with names that start with the database name) remain in that directory when your device is rebooted then the last connection with the database was definitely not sqlite3_close()-ed properly. This sort of thing happens if the device doesn't wait for the app to quit before it shuts down. If you can tell us that there are definitely no journal files, that'll cut of a bunch of possibilities. Once you've done that, you might write a tiny C program which opens the database in C (fopen(), or something like that), reads the first byte out of it, writes the same value back, and closes it. See whether you get any errors from that program. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users