我正在使用pyodbc
來管理我的數據庫連接。我試圖連接到OSI PI數據庫,並收到此錯誤:如何將Python 2.6連接到OSI PI?
pyodbc.Error: ('IM002', "[IM002] [OSI][PI ODBC][PI]PI-API Error <pilg_getdefserverinfo> 0 (0) (SQLDriverConnectW); [01000] [Microsoft][ODBC Driver Manager] The driver doesn't support the version of ODBC behavior that the application requested (see SQLSetEnvAttr). (0)")
與供應商交談後,我得到了這樣的響應: Looks like pyodbc is written against ODBC 3.x. The OSI PI ODBC driver is using ODBC 2.0. The python ODBC driver manager will convert most ODBC 3 calls on the fly to ODBC 2 ones. Anything added to 3, however, will obviously fail. You would need to find some way to make sure that your only using 2.0 compliant ODBC calls. Currently their is not a PI ODBC driver that is compliant with ODBC 3.0.
我的代碼我相當簡單只是試圖在這一點上連接:
import pyodbc
constr = 'DRIVER={PI-ODBC};SERVER=myserver;UID=MY_UID'
pyodbc.pooling=False
conn = pyodbc.connect(constr) # Error at this line
conn.close()
有沒有人連接到OSI PI的Python?如果是這樣,你是怎麼做到的?如果不是,並且您仍然使用OSI數據庫中的數據,那麼最終如何訪問它?
我有使用'R'' RODBC'軟件包連接到PIODBC的問題。症狀是所有查詢返回零行。解決的辦法是設置'RODBC'一次獲取一行('rows_at_time = 1')以及('believeNRows = FALSE'),因爲PI ODBC驅動程序搞亂了行數。 http://stackoverflow.com/q/7425100/176995 – 2012-06-12 00:52:13