1
我試圖從SQL Server CE數據庫(.sdf
文件格式)中將表加載到Python(3.5.1)中。這是我一直在玩弄什麼:加載,通過Python查詢SQL Server CE 4.0數據庫文件
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;
等連接字符串中的在線但搜索後沒有運氣。有人可以幫我用正確的連接字符串,或者如果我在這裏做了其他任何錯誤?
編輯:在connstr
沒有一個Python專家,但爲什麼你有:數據源==而不是數據源=? – ErikEJ
我嘗試了==和=(仍然學習Python,我在R中完成了大部分工作,並且只使用python來讀取這個sdf文件)。編輯我的帖子。 – tvns
我一直在使用pyodbc沒有任何錯誤。 –