pymssql:连接到数据库的唯一作品有时 [英] pymssql: Connection to the database only works sometimes

查看:1045
本文介绍了pymssql:连接到数据库的唯一作品有时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着使用Python的pymssql连接到SQL Azure的服务器。问题是,下面的脚本作品,但只是偶尔,其他时候我得到这个错误:

I'm trying to connect to Azure SQL server using Python's pymssql. The problem is that the following script works but only sometimes, the other times I get this error:

_mssql.MSSQLDatabaseException:(20002,b'DB-Lib的错误信息20002,严重性9:\\ nAdaptive服务器连接失败\\ n')

_mssql.MSSQLDatabaseException: (20002, b'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed\n')

这是我使用的脚本:

import pymssql
conn = pymssql.connect(server='x', user='x', password='x', database='x')
cursor = conn.cursor()
cursor.execute('SELECT * FROM customers');
row = cursor.fetchone()
while row:
    print (str(row[0]) + " " + str(row[1]) + " " + str(row[2]))
    row = cursor.fetchone()

这会对我帮助很大,如果有人能告诉我为什么这上面的脚本作品只是有时和时代我得到的其余Adaptive Server连接失败错误。

It would help me greatly if someone can tell me why this above script works only sometimes and rest of the times I get the "Adaptive Server connection failed" error.

推荐答案

我审查了这些那么老线程<一个href=\"http://stackoverflow.com/questions/11721403/read-from-the-server-failed-when-trying-to-connect-to-sql-azure-from-tsql\">Read从服务器试图从TSQL 连接到SQL-蔚蓝的时候和失败的<一个href=\"http://stackoverflow.com/questions/10889294/what-is-tds-protocol-version-8-0-and-why-should-i-use-it\">What是TDS协议版本8.0以及我为什么要使用它?。
这个问题似乎通过freetds的的版本错误引起的。

I reviewed these SO old threads Read from the server failed when trying to connect to sql-azure from tsql and What is TDS Protocol Version 8.0 and why should I use it?. The issue seems to be caused by using the wrong version of FreeTDS.

我发现在freetds的页面的关键官方网站 HTTP ://www.freetds.org/faq.html#Does.FreeTDS.support.Microsoft.servers

I found the key at the page of FreeTDS offical website http://www.freetds.org/faq.html#Does.FreeTDS.support.Microsoft.servers.

有是产品 HTTP TDS协议的版本表://www.freetds。组织/ userguide / choosingtdsprotocol.htm

在这里输入的形象描述

freetds的别名将这个版本7.1的向后兼容性的原因,但是这应该是由于未来的兼容性问题是可以避免的。参见下面注意,过时的版本。

FreeTDS will alias this version to 7.1 for backwards compatibility reasons, but this should be avoided due to future compatibility concerns. See note below on obsolete versions.

如果您使用pymssql在Linux上freetds的,我想你需要检查配置文件freetds.conf在路径的/ etc / freetds的/.

If you use pymssql with FreeTDS on linux, I think you need to check the configuration file "freetds.conf" at the path /etc/freetds/.

这是我的Azure以下SQL Server配置:

This is my configuration for Azure SQL Server below:

# A typical Microsoft server
[egServer70]
        host = <database_name>.database.windows.net
        port = 1433
        tds version = 7.3

您可以尝试使用freetds的工具'TSQL'到命令测试天青SQL服务器的连接 TSQL -H&LT;数据库名称&GT; .database.windows.net -u用户名-D数据库名 - p 1433 -P密码

You can try to test the connection to Azure SQL server by using freetds tool 'tsql' to command 'tsql -H <database_name>.database.windows.net -U Username -D DatabaseName -p 1433 -P Password' .

最好的问候。

这篇关于pymssql:连接到数据库的唯一作品有时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆