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“.
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 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!
Thanks!
:)
Thanks for the great tip.
Very subtle….
;o))
Thanks. You really helped me ;)
You saved my day!!!
I ran into the same problem today.
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.
yeah..thx for the information..
i have a same problem..
look like, i must try other idea..so the the DB not error anymore
Thanks! Full path required…
Thank you!! Write permissions on the db file AND its container! Who would have thought?!!
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
Thank you guys, I’m glad this article is helpful!
Thanks for posting this hint so that google could find it for me :-)
Reinout
Thanks, that was it.
Oh man, you just saved me – gonna find you and kiss your head
Thanks you so much. It is very useful for me
thanks.. it was very useful . I was trying to look at this solution for few hours thinking that after modifying the writing permission on the file it was enough.
Oh man, I never would have figured this one out. Thank you very much.
I wish I could also say Thanks Thanks :)
But I am trying from C code to open/create the db file:
The Path is “/data/databases/mp3.db” and I use CREATE Flag to create the file and directory if it doesn’t exists.
sqlite3_open_v2(Path, .., SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE), NULL);
And it returns error code 14 /* Unable to open the database file */
Could you please try to help me as well :)
Thanks
It seems you are trying to create directories under root directory. If your code wasn’t executed by root user, it usually doesn’t have permission to do so.
I am an apache newbie. How can I set the server to have wrtie access to teh sqlite database file and the folder ? I have done the below and it still doesnot work.
sudo chmod -R 777 databasefolder
Pingback: error SQLite3 Unable to Open Database File « Desarrollo Linux y software libre
Thanks so much for this post. I could have been stalled by this for a long time if I hadn’t come across this post. Thanks to you, I only wasted about five minutes debugging this error.
Tks a lot! I have been confused it for a long time!Tks again very much!
pfuuu !
i ran in the same probleme, i tought about that, but i have prefered to search before spending days on it ! you help me thanks !
It’s really useful, thanks
It’s always a pleasure to find a simple solution for an annoying problem. Thanks a lot
thanks for this great tip.
Thanks :-D
Reblogged…
This problem really should be clarified in future releases of sqlite.
You’ve just saved me. I was going round in circles trying to work this out. Also realised the folder needs delete permissions too for the journal file!
u saved me, tnx
Thanks! I was wondering why the journal file was just staring at me.
I have wasted hours and hours on this issue. Thanks for your tip, which helped me get past this problem.
Fortunately, your post shows up as one of the first for “unable to open database file 14″. So I only wasted a few minutes. Thanks! :)
Thank you so much!!!!
You have no idea how helpful it was!
I could finally figure out why windows service was refusing to write to the sqlite database.
Thanks again!
You made my day!
hEY DUDE THANKS A TON…..IT WORKS!!!
Thanks a looooot :)
Thanks its helped
Thanks a lot, this helped me. And to add a bit, the whole path does not need to be web server writable, only the directory for the database file and the database file itself.
Seems to work both for CGI style and mod_python style Python scripts.