【发布时间】:2010-06-18 20:11:42
【问题描述】:
我正在使用来自http://www.ironpython.info/index.php/Accessing_SQL_Server 的源代码使用python 查询MS SQL:
import clr
clr.AddReference('System.Data')
from System.Data import *
TheConnection = SqlClient.SqlConnection
("server=yourserver;database=News;uid=sa;password=password;timeout=0")
TheConnection.Open()
MyAction = SqlClient.SqlCommand("Select Headline from News", TheConnection)
MyReader = MyAction.ExecuteReader()
while MyReader.Read():
print MyReader[0]
MyReader.Close()
TheConnection.Close()
我刚刚添加了timeout=0,但还是得到了:
EnvironmentError: System.Data.SqlClient.SqlException (0x80131904): Timeout
expired. The timeout period elapsed prior to completion of the operation
or the server is not responding.
我用timeout=1000000 尝试过,但仍然遇到同样的错误。
如果我使用 MSSQL 客户端在同一台机器上运行相同的 SQL,那就完全没问题了。你知道如何避免这个超时异常吗?
【问题讨论】:
标签: python sql-server ironpython pymssql