【Python开发及测试】tsql连接正常,pymssql无法连接

先来看异常:

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:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed\n')

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:\nGeneral SQL Server error: Check messages from the SQL Server\nDB-Lib error message 20002, severity 9:\nAdaptive Server connection failed\n')

 

使用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这种方式

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(Python开发及测试)