我正在尝试将表从SQL Server CE数据库(.sdf文件格式)加载到Python3.5.1中。这是我一直在尝试的:
import adodbapi
file="C:\\TS\\20160406_sdfPyt\\HC.sdf"
connstr = 'Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source=%s;' %file
conn = adodbapi.connect(connstr)这将抛出错误消息
Traceback (most recent call last):
File "C:\Users\TS\AppData\Local\Programs\Python\Python35\lib\site-packages\adodbapi\adodbapi.py", line 112, in connect
co.connect(kwargs)
File "C:\Users\TS\AppData\Local\Programs\Python\Python35\lib\site-packages\adodbapi\adodbapi.py", line 274, in connect
self.connector.Open() # Open the ADO connection
File "<COMObject ADODB.Connection>", line 3, in Open
File "C:\Users\TS\AppData\Local\Programs\Python\Python35\lib\site-packages\win32com\client\dynamic.py", line 287, in _ApplyTypes_
result = self._oleobj_.InvokeTypes(*(dispid, LCID, wFlags, retType, argTypes) + args)
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Service Components', 'Format of the initialization string does not conform to the OLE DB specification.', None, 0, -2147217805), None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
conn = adodbapi.connect(connstr)
File "C:\Users\TS\AppData\Local\Programs\Python\Python35\lib\site-packages\adodbapi\adodbapi.py", line 116, in connect
raise api.OperationalError(e, message)
adodbapi.apibase.OperationalError: (com_error(-2147352567, 'Exception occurred.', (0, 'Microsoft OLE DB Service Components', 'Format of the initialization string does not conform to the OLE DB specification.', None, 0, -2147217805), None), 'Error opening connection to "Provider=Microsoft.SQLSERVER.CE.OLEDB.4.0;Data Source==C:\\TSrinivas\\20160406_sdfPyt\\HC.sdf;"')我试着把
SSCE:Max Database Size=3999;Persist Security Info=True;在线搜索后在连接字符串中等等,但没有运气。有人能帮我找出正确的连接字符串吗,或者如果我在这里做错了什么?
编辑:在连接字符串中将'==‘更改为'=’
发布于 2016-04-12 04:02:30
我从https://www.microsoft.com/en-us/download/details.aspx?id=5783重新安装了SQL ServerCE3.5(首先是x86,然后是x64),并将连接字符串更改为
connstr = """Provider=Microsoft.SQLSERVER.CE.OLEDB.3.5;Data Source=C:\\TSrinivas\\20160406_sdfPyt\\HazardCache.sdf;"""这可以在4.0数据库上运行!我早些时候试过了,但它没有工作,但不知何故重新安装完成了工作。我用的是adodbapi。
https://stackoverflow.com/questions/36508240
复制相似问题