[Tutor] Cannot open SQLite database

spir denis.spir at free.fr
Wed Feb 24 11:58:06 CET 2010

On Wed, 24 Feb 2010 09:38:56 +0100
Timo <timomlists at gmail.com> wrote:

> Hello all, my program uses SQLite as database and everything worked fine 
> until now.
> I have over 3000 downloads of my program, but I got 2 mails this week 
> from people who get this error:
> OperationalError: unable to open database file
> I searched the net, and all problems seem to be of a not writeable 
> directory or passing a tilde to connect to the database.
> As far as I know, this isn't the case with my program.
> Here is some code:
> # Get the application data folder
> # This will return: C:\Documents and Settings\user\Application Data\myapp
> PREFDIR = os.path.join(os.environ['APPDATA'], 'myapp')
> # Connect to the database
> def db_connect():
>      conn = sqlite3.connect(os.path.join(PREFDIR, 'myapp.db')) # This 
> line gives the error
>      conn.text_factory = str
>      cursor = conn.cursor()
>      return (conn, cursor)

I would first add debug lines

    print os.path.join(PREFDIR, 'myapp.db')
    print os.path.exists(os.path.join(PREFDIR, 'myapp.db'))
    print open(os.path.join(PREFDIR, 'myapp.db'), 'r')
    print open(os.path.join(PREFDIR, 'myapp.db'), 'a')
    conn = sqlite3.connect(os.path.join(PREFDIR, 'myapp.db'))

to check name, existence, read access right, write access right, of the file.


la vita e estrany


More information about the Tutor mailing list