Python sqlite3 OperationalError: Unable to open database file

Viewed 33

I'm trying to code a bot using sqlite3 in python, this is the code I'm have trouble with:

def init_db():
    with closing(connect_db()) as db:
        with open("database/schema.sql", "r") as f:
            db.cursor().executescript(f.read())
        db.commit()


def connect_db():
    return sqlite3.connect("database\database.db")


bot.config = config
bot.db = connect_db()

This is my error:

    File "c:\Users\Jaxon\OneDrive\Documents\CODE\Visual Studio Code\Pancake's Bot\bot.py", line 
    306, in <module>
    init_db()
    File "c:\Users\Jaxon\OneDrive\Documents\CODE\Visual Studio Code\Pancake's Bot\bot.py", line 54, in init_db
    db.cursor().executescript(f.read())
   sqlite3.OperationalError: unable to open database file

This is my File system, as you can see, the database.db exists: files

I have tried recreating the databse, running without the database, trying with these paths:

database/database.db
/database/database.db
\database\database.db
database\database.db

How do I solve this?!?

0 Answers
Related