用pymssql连接本地数据库,每次都得3分钟才能连上?

horizon668 2017-02-20 11:42:57
如题,我用pymssql连接本地数据库,每次都得3分钟才能连上,用SQLDBX都是直接就能等进去的。

d1=datetime.now()
print(d1)
hh=pymssql.connect(host='USER-20160409WQ',user='sa',password='sa',database='STS_15')
d2=datetime.now()
print(d2,d2-d1)
cu=hh.cursor()
d3=datetime.now()


2017-02-20 11:34:52.632141
2017-02-20 11:38:52.814140 0:04:00.181999

2017-02-20 11:38:52.814140 0:00:00
2017-02-20 11:38:52.818141 0:00:00.004001
...全文
349 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
u012976913 2017-06-27
  • 打赏
  • 举报
回复
你好,请问你是怎么配置pymssql环境的,我的连不上库,总报错pymssql.OperationalError: (18456, "\xe7\x94\xa8\xe6\x88\xb7 'sa' \xe7\x99\xbb\xe5\xbd\x95\xe5\xa4\xb1\xe8\xb4\xa5\xe3\x80\x82DB-Lib error message 20018, severity 14:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (221.193.232.189:14333)\n")
混沌鳄鱼 2017-02-20
  • 打赏
  • 举报
回复
可能是你有DNS有问题,你连接本地数据库应该 建议用 host='localhost' 或 host='127.0.0.1'
horizon668 2017-02-20
  • 打赏
  • 举报
回复
引用 1 楼 xpresslink 的回复:
可能是你有DNS有问题,你连接本地数据库应该 建议用 host='localhost' 或 host='127.0.0.1'
用host='localhost' 2017-02-20 13:35:45.494138 2017-02-20 13:36:45.580268 0:01:00.086130 连接时间为1分钟 用host='127.0.0.1' 2017-02-20 13:38:52.477882 2017-02-20 13:38:52.555892 0:00:00.078010 感谢!

37,743

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧