Closed takoau closed 1 year ago
@denisenkom we're struggling with this same problem, and @takoau 's PR: https://github.com/denisenkom/pytds/pull/138 fixes it.
@denisenkom we're struggling with this same problem, and @takoau 's PR: #138 fixes it.
@ecly I'm struggling with codecov. Is there anything I can do to make it pass? I have no knowledge on what codecov is. I am a database admin not a dev.
Pull request is https://github.com/denisenkom/pytds/pull/138
Currently readonly flag does not work on AG database. The type flag is not correct. It should be 2<<4 instead of 2<<5. if login.readonly: type_flags |= (2 << 5) w.put_byte(type_flags)
Secondly readonly flag not working for SSPI authentication. Socket connects twice if you connect over AG listeners. One connecting to AG listener and second one actually connect to database server. However second connection always fails as SPN not changing to database host. It throws SEC_E_INVALID_HANDLE at the end.
conn = pytds.connect(dsn='TestAG', readonly=True, port=1901, use_sso=True, database='dba') SPN is : MSSQLSvc@TestAG:1901 Opening socket to TestAG:1901 Get socket done SPN is : MSSQLSvc@TestAG:1901 Opening socket to TestDB:1901 Get socket done
Traceback (most recent call last): File "C:\Users\mau.conda\envs\venv\lib\site-packages\IPython\core\interactiveshell.py", line 3457, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "", line 1, in
conn = pytds.connect(dsn='TestAG', readonly=True, port=1901, use_sso=True, database='dba')
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds__init.py", line 1362, in connect
conn._open(sock=sock)
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds__init.py", line 388, in _open
self._try_open(timeout=retry_time, sock=sock)
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds__init__.py", line 370, in _try_open
self._connect(host=host, port=port, instance=instance, timeout=timeout, sock=sock)
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds\init__.py", line 327, in _connect
timeout=timeout)
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds\init__.py", line 320, in _connect
route = conn.login(login, sock, self._tzinfo_factory)
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds\tds.py", line 1705, in login
self._main_session.tds7_send_login(login)
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds\tds.py", line 1389, in tds7_send_login
auth_packet = login.auth.create_packet()
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds\login.py", line 71, in create_packet
output_buffers=[(sspi.SECBUFFER_TOKEN, buf)])
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds\sspi.py", line 377, in create_context
byref(ctx._ts))
File "C:\Users\mau.conda\envs\venv\lib\site-packages\pytds\sspi.py", line 164, in ret_val
raise Exception('SSPI Error {0}'.format(Status.getname(value)))
Exception: SSPI Error SEC_E_INVALID_HANDLE