2016-11-15 83 views
0
設置爲

連接字符串如下:奇UTF-8的錯誤嘗試連接到MS SQL Server的

# -*- coding: utf-8 -*- 
import pypyodbc 
connection = pypyodbc.connect("DRIVER={SQL Server};SERVER='MyServer';UID='uname';PWD='pwd';DATABASE='mydb'") 

收到以下錯誤:

UnicodeDecodeError: 'utf-32-le' codec can't decode bytes in position 0-1: truncated data 

回答

0

你需要仔細檢查是什麼在ODBC .ini文件中,該部分的ServerName與freetds.conf文件中的名稱相同。

例如:

ODBC.INI

[old_flood] 
Driver = FreeTDS 
Description = RTS Old Flood 
ServerName = old_flood  <----- this must be the same as the name in 
freetds.conf 

freetds.conf

[old_flood]     <----- This is the same as the ServerName above 
    host = <server ip address> 
    port = <server port> 
    tds version = 8.0 

您還需要確保你所創建的數據庫用戶有你的數據庫適當的訪問試圖讀/寫。對我而言,我只需要閱讀權限。您可以在SQL Server Management Studio的安全節點中進行設置。右鍵點擊用戶,然後進入用戶映射。檢查相應的數據庫,確保突出顯示數據庫,然後在底部設置數據庫角色。