Closed tatarinova closed 7 years ago
Your statement
connection_string = "DRIVER={SQLITE3}; SERVER=localhost; DATABASE=database; Trusted_connection=yes; DNS=dns"
produces a connection string that is malformed, so the SQLite ODBC driver treats the whole thing as the database name. When I run your code and then look in my home directory I see
gord@xubuntu64-nbk1:~$ ls -l
total 36
drwxr-xr-x 2 gord gord 4096 Jul 21 18:19 Desktop
drwxr-xr-x 2 gord gord 4096 Jul 21 18:19 Documents
drwxr-xr-x 3 gord gord 4096 Aug 10 06:59 Downloads
-rw-r--r-- 1 gord gord 0 Aug 10 07:17 DRIVER={SQLITE3}; SERVER=localhost; DATABASE=database; Trusted_connection=yes; DNS=dns
drwxr-xr-x 2 gord gord 4096 Jul 21 18:19 Music
drwxr-xr-x 2 gord gord 4096 Jul 21 18:19 Pictures
drwxr-xr-x 2 gord gord 4096 Jul 21 18:19 Public
-rw-rw-r-- 1 gord gord 434 Aug 10 07:17 sqlite_test.py
drwxr-xr-x 2 gord gord 4096 Jul 21 18:19 Templates
drwxr-xr-x 2 gord gord 4096 Jul 21 18:19 Videos
Notice the file named "DRIVER={SQLITE3}; SERVER=localhost; DATABASE=database; Trusted_connection=yes; DNS=dns".
Not only do you include the database
variable as a literal, but you also include connection parameters that have no meaning to the SQLite ODBC driver, e.g., Trusted_connection
.
Your connection string should look more like this:
database = 'OPER_odc.db' # the DB is located in the same place as the script; also tried with the absolute path
connection_string = "DRIVER=SQLITE3;DATABASE=" + database
Or, if you want to use your DSN (not "DNS"), then just use
connection_string = "DSN=TestDB"
Great! :+1: Thank you very much! It work now. Just my remark for other people: no spaces in a connection string (I did not know before), otherwise we have something like:
pyodbc.Error: ('HY000', '[HY000] [unixODBC][SQLite]connect failed (14) (SQLDriverConnect)')
Hello,
I got this error:
while I run this simple script:
My $HOME/.odbc.ini is the following:
The table 'SITES' exists:
Also, when I connect to the DB using sqlite3 library, it works ok.
Environment