On Saturday, October 22, 2011 at 7:03:59 AM UTC-4, João Silva wrote:
>
> Hello everyone,
>
> I'm having a problem connecting to SQLite database files with
> SQLAlchemy. :memory: databases work just fine, but whenever I'm trying
> to access a file, the following happens:
>
>
> Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit
> (AMD64)] on win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> from sqlalchemy import create_engine
> >>> import os.path
> >>> os.path.exists('test.db')
> False
> >>> engine = create_engine('sqlite:///test.db')
> >>> engine.connect
> <bound method Engine.connect of Engine(sqlite:///test.db)>
> >>> engine.connect()
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\base.py", line 2310, in connect
> return self._connection_cls(self, **kwargs)
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\base.py", line 872, in __init__
> self.__connection = connection or engine.raw_connection()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\base.py", line 2396, in raw_connection
> return self.pool.unique_connection()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 169, in unique_connection
> return _ConnectionFairy(self).checkout()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 370, in __init__
> rec = self._connection_record = pool._do_get()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 757, in _do_get
> return self._create_connection()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 174, in _create_connection
> return _ConnectionRecord(self)
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 255, in __init__
> self.connection = self.__connect()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 315, in __connect
> connection = self.__pool._creator()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\strategies.py", line 80, in connect
> return dialect.connect(*cargs, **cparams)
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\default.py", line 275, in connect
> return self.dbapi.connect(*cargs, **cparams)
> sqlalchemy.exc.OperationalError: (OperationalError) unable to open
> database file
> None None
>
>
> The same happens after having created the database using the sqlite3
> module and then trying to connect to it via SQLAlchemy.
>
> >>> import sqlite3
> >>> conn = sqlite3.connect('test.db')
> >>> conn.execute('create table bla(id int primary key);')
> <sqlite3.Cursor object at 0x0000000002FA62D0>
> >>> conn.close()
> >>> os.path.exists('test.db')
> True
> >>> engine = create_engine('sqlite:///test.db')
> >>> engine.connect()
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\base.py", line 2310, in connect
> return self._connection_cls(self, **kwargs)
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\base.py", line 872, in __init__
> self.__connection = connection or engine.raw_connection()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\base.py", line 2396, in raw_connection
> return self.pool.unique_connection()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 169, in unique_connection
> return _ConnectionFairy(self).checkout()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 370, in __init__
> rec = self._connection_record = pool._do_get()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 757, in _do_get
> return self._create_connection()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 174, in _create_connection
> return _ConnectionRecord(self)
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 255, in __init__
> self.connection = self.__connect()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\pool
> .py", line 315, in __connect
> connection = self.__pool._creator()
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\strategies.py", line 80, in connect
> return dialect.connect(*cargs, **cparams)
> File
> "C:\Python27\lib\site-packages\sqlalchemy-0.7.2-py2.7.egg\sqlalchemy\engi
> ne\default.py", line 275, in connect
> return self.dbapi.connect(*cargs, **cparams)
> sqlalchemy.exc.OperationalError: (OperationalError) unable to open
> database file
> None None
>
> So have you got any idea on what might be problem here?
>
>
> --
> João Silva
>
For those still unable to fix this error here is a simple tutorial i
created. Hopefully it helps someone out there and they don't have to spend
hours like me trying to squash it!
http://pythonhowto.com/operationalerror-unable-to-open-database-file-using-sqlite3/
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.