. Advertisement .
. Advertisement .
OperationalError: unable to open database file
occurred when I do: 1) an empty database. 2) the database and the unit test left behind. 3) no database at all.. I’ve tried to fix it for some days but have not resolved it yet. Can someone suggest a relevant solution to fix the sqlite3 operationalerror unable to open database file issue? Much appreciate your support.
This error happens because the code which you are running in a path is not compatible with your definite path for the database. I have found another reason in your code:
If you execute the code inside
folder Aor somewhere else that does not contain a
folder A, you will get the same error. The reason is that if the database file does not exist, SQLite will creat it instead of the folder.
You can fix your error by using a
try-exceptexpression to wrap your connection command and creating the folder if it increases
import sqlite3 as lite from os import mkdir
In addition, you need to check:
1. Is the application being tested on the same machine as it is being run on?
2. Are you able to run it while it’s being tested (or have you used it with the same user)?
3. Is the
/tmpdirectory on the disk full? (If you’re on Unix, you can find out with
4. Are the permissions on the
/tmp/cerdirectory “odd”? (In order to handle things like the commit log, SQLLite must be able to generate new files).
5. Is that database still used by the unit test code? (Concurrent openings are feasible with a contemporary SQLite and the correct filesystem — however
/tmpis almost always on the right kind of FS, so it’s probably not that — but it’s still not recommended).
6. Is the development code attempting to write to that database, or is something “smart” catching you off guard and leading it to attempt to open something else? (I’ve been caught out in the past by this in my code; don’t assume it won’t happen to you…).
7. Do you run your unit tests with the same SQLite version as your production code?
It’s possible that the production system doesn’t have a
/tmp/cerdirectory if you’re not on the same machine. It is self-evident that this must be solved first. Similarly, if you’re running as several users on the same machine, you are likely to run into permissions/ownership issues. Another essential problem is a lack of disk space. I don’t believe it’s the last three, but if the more obvious deployment issues have been resolved, they’re worth reviewing. If none of the following apply, you’ve encountered an unusual situation and will need to provide considerably more information (it might even be a bug in SQLite, but knowing the developers of it, I believe that to be quite unlikely).
It worked for me.
Notice: In the full path, there are double slashes
Python v2.7 for Win 7 Enterprise and Win Xp Professional
We hope this helps.