SQL Server Compact connection error in Python

820 views Asked by At
connstr =  """Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;DataSource=first.sdf;"""
conn = adodbapi.connect(connstr)
cur = conn.cursor()
getresult="select * from ft"
cur.execute(getresult)
result=cur.fetchall()

How can I solve the following error?

Traceback (most recent call last):
  File "e:\python1\sqlcompactdb\compact.py", line 7, in <module>
    connection = adodbapi.connect(connection_string)
  File "C:\Users\khan\AppData\Local\Programs\Python\Python36-32\lib\site-packages\adodbapi\adodbapi.py", line 116, in connect
    raise api.OperationalError(e, message)
adodbapi.apibase.OperationalError: (InterfaceError("Windows COM Error: Dispatch('ADODB.Connection') failed.",), 'Error opening connection to "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0; Data Source=E:\\python1\\sqlcompact\\first.sdf;"')
1

There are 1 answers

0
johnDanger On

As the error implies, this issue stems from an error when the module tries to make an ADO database connection.

Specifically, when the following code executes

pythoncom.CoInitialize()
c = win32com.client.Dispatch('ADODB.Connection')

This is most likely due to hardware issues like the lack of the correct provider for the needed connection.

Solutions to a similar problem can be found at Connecting to SQLServer 2005 with adodbapi