【Python開発及びテスト】tsql接続正常、pymssql接続不可
3118 ワード
まず異常を見てみましょう.
Traceback (most recent call last): File "pymssql.pyx", line 635, in pymssql.connect (pymssql.c:10734) File "_mssql.pyx", line 1902, in _mssql.connect (_mssql.c:21821) File "_mssql.pyx", line 637, in _mssql.MSSQLConnection.__init__ (_mssql.c:6581) File "_mssql.pyx", line 1630, in _mssql.maybe_raise_MSSQLDatabaseException (_mssql.c:17524) _mssql.MSSQLDatabaseException: (40532, b'Cannot open server "1433D"requested by the login. The login failed.DB-Lib error message 20018, severity 20:General SQL Server error: Check messages from the SQL ServerDB-Lib error message 20002, severity 9:Adaptive Server connection failed')
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "auto_insert_sql.py", line 129, in fire.Fire() File "/Users/nitb/.pyenv/versions/env364/lib/python3.6/site-packages/fire/core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "/Users/nitb/.pyenv/versions/env364/lib/python3.6/site-packages/fire/core.py", line 366, in _Fire component, remaining_args) File "/Users/nitb/.pyenv/versions/env364/lib/python3.6/site-packages/fire/core.py", line 542, in _CallCallable result = fn(*varargs, **kwargs) File "auto_insert_sql.py", line 78, in insert sqlHelp = ZymssqlHelper(filepath) File "auto_insert_sql.py", line 30, in __init__ self.cursor = self.connect().cursor() File "auto_insert_sql.py", line 33, in connect return pymssql.connect(server='mhstlogsqlpass01.database.chinacloudapi.cn', user='mduser', password='E3g707W2h237', database='MD_Base') File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824) pymssql.OperationalError: (40532, b'Cannot open server "1433D"requested by the login. The login failed.DB-Lib error message 20018, severity 20:General SQL Server error: Check messages from the SQL ServerDB-Lib error message 20002, severity 9:Adaptive Server connection failed')
tsql検出を使用するのも正常です.
tsql -H mhstlogsqlpass01.database.chinacloudapi.cn -p 1433 -U mduser -P E3g707W2h237
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> help
2> GO
Msg 2812 (severity 16, state 62) from mhstlogsqlpass01 Line 1:
"Could not find stored procedure 'help'."
1> select @@version
2> go
Microsoft SQL Azure (RTM) - 12.0.2000.8
Jun 8 2018 18:18:54
Copyright (C) 2018 Microsoft Corporation
(1 row affected)
1> exit
理由:
userは使用する必要がありますusername@servernameこの方式
Traceback (most recent call last): File "pymssql.pyx", line 635, in pymssql.connect (pymssql.c:10734) File "_mssql.pyx", line 1902, in _mssql.connect (_mssql.c:21821) File "_mssql.pyx", line 637, in _mssql.MSSQLConnection.__init__ (_mssql.c:6581) File "_mssql.pyx", line 1630, in _mssql.maybe_raise_MSSQLDatabaseException (_mssql.c:17524) _mssql.MSSQLDatabaseException: (40532, b'Cannot open server "1433D"requested by the login. The login failed.DB-Lib error message 20018, severity 20:General SQL Server error: Check messages from the SQL ServerDB-Lib error message 20002, severity 9:Adaptive Server connection failed')
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "auto_insert_sql.py", line 129, in fire.Fire() File "/Users/nitb/.pyenv/versions/env364/lib/python3.6/site-packages/fire/core.py", line 127, in Fire component_trace = _Fire(component, args, context, name) File "/Users/nitb/.pyenv/versions/env364/lib/python3.6/site-packages/fire/core.py", line 366, in _Fire component, remaining_args) File "/Users/nitb/.pyenv/versions/env364/lib/python3.6/site-packages/fire/core.py", line 542, in _CallCallable result = fn(*varargs, **kwargs) File "auto_insert_sql.py", line 78, in insert sqlHelp = ZymssqlHelper(filepath) File "auto_insert_sql.py", line 30, in __init__ self.cursor = self.connect().cursor() File "auto_insert_sql.py", line 33, in connect return pymssql.connect(server='mhstlogsqlpass01.database.chinacloudapi.cn', user='mduser', password='E3g707W2h237', database='MD_Base') File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824) pymssql.OperationalError: (40532, b'Cannot open server "1433D"requested by the login. The login failed.DB-Lib error message 20018, severity 20:General SQL Server error: Check messages from the SQL ServerDB-Lib error message 20002, severity 9:Adaptive Server connection failed')
tsql検出を使用するのも正常です.
tsql -H mhstlogsqlpass01.database.chinacloudapi.cn -p 1433 -U mduser -P E3g707W2h237
locale is "zh_CN.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> help
2> GO
Msg 2812 (severity 16, state 62) from mhstlogsqlpass01 Line 1:
"Could not find stored procedure 'help'."
1> select @@version
2> go
Microsoft SQL Azure (RTM) - 12.0.2000.8
Jun 8 2018 18:18:54
Copyright (C) 2018 Microsoft Corporation
(1 row affected)
1> exit
理由:
def connect(self):
return pymssql.connect('mhstlogsqlpass01.database.chinacloudapi.cn', '[email protected]', 'E3g707W2h237', 'MD_Base')
userは使用する必要がありますusername@servernameこの方式