Unable to open database error?

An Annoture user can’t run the application because the Aperture SQLite3 database can not be opened. He’s getting the error from the program and from the command line when manually trying to access the database.

Unable to open database file

Any Mac OS X and SQLite3 gurus know why this might be the case. This is the first time I’ve encountered where a user can’t access the database. He’s running Aperture 1.5.1 on OS X 10.4.8.

4 thoughts on “Unable to open database error?

  1. Brian

    — I wrote this stuff last, but think it’s better up top… —

    Basically, “unable to open database file” is too general :-)

    Some ideas:

    Get the user to use the app without anything else that could possible have the database currently open — the contention test

    Try to get the database file and analyze it with the free tools from sqlite, or have your user do this and report back — the corruption test

    Familiarize yourself with the sqlite api and write some code to poke at the database file to get a real error code back.

    Compile sqlite locally into a static lib, link against that lib in your app, and walk through the code to see where it’s returning the error

    — the ramble —

    I haven’t worked with OSX, but have done a lot of work with sqlite3…. Can you be more specific on the problem? Is there a sqlite error code being returned? Something fairly common I see happen is someone uses the sqlite3 command line tools (from sqlite.org) from a later version of sqlite than what is statically linked into whatever ‘real’ app from which they usually access the database (Annoture in this case). If they perform an operation in the cmdline tool that results in a write to the database, the database version is silently “upgraded” to whatever version is in the cmdline tool. This may be greater-than the version Annoture is using. If this happens, Annoture’s sqlite will not be able to open the database, as one of the firs things that occurs is a version-check, “Hey this version of the database is greater than the version I know how to use, better exit!”

    Can you get your hands on his database? If you can get the database , you can run some analysis tools from sqlite to get some diagnostics. In my experience, when a sqlite database goes corrupt, it’s often spot corruption, and you can select records from around the bad part. Are you doing sqlite calls directly from your app? If so, how are you handling contention on the database? Are you using sqlite’s built-in busy handler? If your access to sqlite is through someone elses api (ie, you’re not calling sqlite3_prepare, and the other methods from sqlite.org/capi3ref.html) it’d be interesting to at least know how it handles two people getting write access to the database at the same time. Sqlite’s default behavior is ‘interesting’ with this.
    Speaking of contention on the database, what’s the usage pattern? Is the database open in another application, then he runs an app (yours, I’m guessing), and the 2nd app returns that error — perhaps after a few seconds? That’s probably contention. The first app may have the database in transaction, the 2nd app comes along, tries to get a lock of some sort (there are a few levels of locking going on in sqlite) and sqlite won’t relinquish the first app’s lock.

  2. Brian:

    Thanks for the excellent suggestions. Let me provide some more information on what’s happening.

    – Annoture is calling sqlite3 from the command line and is not using any API from within Aperture.
    – Annoture does not write anything to Aperture’s sqlite3 database. Timeature does, but Annoture simply calls SELECT statements on the database
    – I had the user try to open the database and make a select call from the command line and the same error appeared.

    “Unable to open database “/Users/XXX/Pictures/Aperture Library.aplibrary/Aperture.aplib/Library.apdb”: unable to open database file”

    – I had the user send me his database file and I was able to open and retrieve information from it using sqlite3 on the command line
    – He says that permissions are set properly on the database. I’ll have him verify this.

    I’ll have him check the version number of sqlite3 on his machine. He’s running 10.4.8 and Aperture 1.5.1, so I’m guessing that they should match what I have running on my machine. We shall see.

    Thanks again for the great response!

  3. Mike Mestnik

    > > Annoture simply calls SELECT statements on the database.
    > Get the user to use the app without anything else that could possible have the database currently open — the contention test

    That’s correct. If the file is open for SELECT statements, then you should have contention issues.

  4. Zorg

    – He says that permissions are set properly on the database. I’ll have him verify this.

    He needs write permission for the folder as well, not only for the .db

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: