How to access a SQL CE database file (sdf) from python (with pyodbc)

21 Views Asked by At

I am on Win10 and python 3.11. Trying to access/read a Compact SQL sdf file with the following script:

import pyodbc 
connstr = 'Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source=RecipeDatabase.sdf;'
cnxn = pyodbc.connect(connstr)

Unfortunately I am getting:

Exception has occurred: InterfaceError
('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Der Datenquellenname wurde nicht gefunden, und es wurde kein Standardtreiber angegeben (0) (SQLDriverConnect)')
  File "C:\Users\clw\source\repos\SQLCEDatenbankTest.py", line 23, in <module>
    cnxn = pyodbc.connect(connstr)
           ^^^^^^^^^^^^^^^^^^^^^^^
pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Der Datenquellenname wurde nicht gefunden, und es wurde kein Standardtreiber angegeben (0) (SQLDriverConnect)')

The sdf file is in the same folder as the script.

What is the correct connectionstring syntax to access the sdf file?

Note: I tried to access with adodbapi, but adodbapi seems to require Python >= 3.9

0

There are 0 best solutions below