|
楼主 |
发表于 2020-1-3 09:55:06
|
显示全部楼层
本帖最后由 maxliu06 于 2020-1-3 10:17 编辑 import pymssql
server = '192.168.0.97'
user = 'sa'
pwd = '123qwe,./'
db = 'a1'
def GetConnect():
conn = pymssql.connect(host=server,user=user,password=pwd,database=db,charset='utf8')
cur = conn.cursor()
if not cur:
raise (NameError,"连接失败")
else:
print("连接成功")
return cur
if __name__ == '__main__':
GetConnect()
以上是网上复制的代码
运行提示错误
Warning (from warnings module):
File "G:/1/python/python_class/连接sql server.py", line 1
import pymssql
DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3, and in 3.9 it will stop working
Traceback (most recent call last):
File "src\pymssql.pyx", line 636, in pymssql.connect
File "src\_mssql.pyx", line 1957, in _mssql.connect
File "src\_mssql.pyx", line 676, in _mssql.MSSQLConnection.__init__
File "src\_mssql.pyx", line 1683, in _mssql.maybe_raise_MSSQLDatabaseException
_mssql.MSSQLDatabaseException: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (192.168.0.97:1433)\nNet-Lib error during Unknown error (10060)\nDB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (192.168.0.97:1433)\nNet-Lib error during Unknown error (10060)\n')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "G:/1/python/python_class/连接sql server.py", line 18, in <module>
GetConnect()
File "G:/1/python/python_class/连接sql server.py", line 9, in GetConnect
conn = pymssql.connect(host=server,user=user,password=pwd,database=db,charset='utf8')
File "src\pymssql.pyx", line 642, in pymssql.connect
pymssql.OperationalError: (20009, b'DB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (192.168.0.97:1433)\nNet-Lib error during Unknown error (10060)\nDB-Lib error message 20009, severity 9:\nUnable to connect: Adaptive Server is unavailable or does not exist (192.168.0.97:1433)\nNet-Lib error during Unknown error (10060)\n')
|
|