2010-06-18 32 views
2

我使用蟒使用源代码查询MS SQL从http://www.ironpython.info/index.php/Accessing_SQL_ServerMS SQL +的Python(IronPython的)超时

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,那就完全没问题。你知道如何避免这种超时异常吗?

回答