SQLite3: Unable to Open Database File

Recently, I’m working on my Skypiea project which is powered by SQLite3 and Python (as CGI script). Yesterday I encountered a program: When the web server ran a CGI script which would update the database, I got an error message said “sqlite3.OperationalError: unable to open database file“.

sqlite

I searched the web and Google told me I need to specify the full path (no ~ or $HOME etc.) of the database file and the web server needs the write permission to the file. Sure, I actually had done both before the exception occurred.

Having being pissed for a while, I finally figured out what was wrong here: The web server needs the write permission to not only the database file, but also the containing directory of that file.

Yea, just simple like that.

This entry was posted in Troubleshooting and tagged , , . Bookmark the permalink.

13 Responses to SQLite3: Unable to Open Database File

  1. Charlie says:

    This had me occupied for an entire afternoon. I was convinced it was a concurrency problem that mutated into a file locking/access error until I found your explanation. Thank you so much!

  2. Jon says:

    Thanks!

    :)

  3. Eddy says:

    Thanks for the great tip.

    Very subtle….

    ;o))

  4. Adams says:

    Thanks. You really helped me ;)

  5. Marc says:

    You saved my day!!!
    I ran into the same problem today.

  6. enkrs says:

    Thanks!! Good your page is the first in google results.

    Actually that makes sense, I guess sqlite creates a temporary file in the directory and rewrites the old file with the temporary on commit.

  7. adit says:

    yeah..thx for the information..
    i have a same problem..
    look like, i must try other idea..so the the DB not error anymore

  8. quandary says:

    Thanks! Full path required…

  9. Jillian says:

    Thank you!! Write permissions on the db file AND its container! Who would have thought?!!

  10. Leandro says:

    I am developing an application for a service desk manager and
    it uses a storage platform SqlLite, broke the
    head all afternoon to find very little detail that just taking everyone’s patience.
    Thanks for the help.
    Brazil – SP

  11. jaux says:

    Thank you guys, I’m glad this article is helpful!

  12. Thanks for posting this hint so that google could find it for me :-)

    Reinout

  13. Gaurav says:

    Thanks, that was it.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>