2016-06-28 70 views
1

我嘗試使用Python連接SQL Azure的,但得到一個錯誤:的Python pymssql:Adaptive Server連接失敗

File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824) 
pymssql.OperationalError: (20002, 'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (myserver:1433)\n') 

freetds.conf:

[global] 
     # TDS protocol version 
     tds version = 7.4 

     # Whether to write a TDSDUMP file for diagnostic purposes 
     # (setting this to /tmp is insecure on a multi-user system) 
     dump file = /tmp/freetds.log 
;  debug flags = 0xffff 

     # Command and connection timeouts 
;  timeout = 10 
;  connect timeout = 10 

     # If you get out-of-memory errors, it may mean that your client 
     # is trying to allocate a huge buffer for a TEXT field. 
     # Try setting 'text size' to a more reasonable limit 
     text size = 64512 

如果我嘗試連接使用TSQL - 連接成功!

我試圖重新編譯freetds的使用參數:

./configure --enable-msdblib --enable-threadsafe --enable-sybase-compat --with-tdsver=7.4 --with-openssl=/usr/bin 

我使用本手冊https://msdn.microsoft.com/en-us/library/mt694094(v=sql.1).aspx

回答

0

我從源碼pymssql和freetds(使用前一篇文章中的選項並在全局配置中設置tds version = 7.3)之後解決它。 Pymssql從源使用命令「python setup.py構建」和下一步安裝在系統「python setup.py install」

0

@Alximik每我的經驗,我不認爲自我重新編譯freetds的是必要的。對於這個問題,我認爲這個問題是由於您對freetds.conf的配置造成的,請參閱我的解答SO線程pymssql: Connection to the database only works sometimes以及下面的示例配置內容。

host = <database_name>.database.windows.net 
port = 1433 
tds version = 7.3 

同時,您可以參考http://www.freetds.org/userguide/freetdsconf.htm進行配置。

+0

謝謝你的回答,但它不能解決我的問題。我從源碼pymssql和freetds解決它(在前一篇文章中有選項,並在全局配置中設置tds version = 7.3) – Alximik

+0

@Alximik感謝您的分享。 –