Skip to content
Advertisement

Connect to SQLite3 server using PyODBC, Python

I’m trying to test a class that loads data from an SQL server given a query. To do this, I was instructed to use sqlite3. Now, the problem is that while the class manages to connect to the real database with ease, I’m struggling to connect with the temporary sqlite3 server that I create, as I cannot figure out what the connection string should look like. I’m using pyodbc in the class to connect with databases. So, has anyone got an idea on what the connection string should look like?

The class looks as follows:

And the temporary sqlite3 server is as follows

So, what I wish to input is something like

EDIT

Okay, I’ve scoured the web a bit and found that a possible connection string is "DRIVER={SQL Server};SERVER=localhost;DATABASE=test.db;Trusted_connection=yes". However, the connection times out after a while and returns the following error message:

Which I found strange as it’s local and as I haven’t specified any password. I’ve also tried specifying the exact path name to no avail.

Best,

Victor

Advertisement

Answer

Solved the problem! Downloaded an ODBC driver for SQLite from http://www.ch-werner.de/sqliteodbc/, and defined the connection string such as

And it worked, hope this helps people!

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement