I'm using pymssql library to connect to MSSQL instance from Python. The problem I face is that I do not know how to get error codes. This is what I have found:
except pymssql.OperationalError as err:
print(err)
it may print this error message:
(18456, b"Login failed for user 'sa'.DB-Lib error message 20018, severity 14:nGeneral SQL Server error: Check messages from the SQL ServernDB-Lib error message 20002, severity 9:nAdaptive Server connection failed (DESKTOP-4JD5C9V\SQLEXPRESS)n")
But I do not know how to reach this 18456 number. In _mssql this worked:
err.number
But in pymssql it is no longer working. I tried to investigate this class with
print(vars(err))
print(err.__dict__)
but they both return {}. So, I do not know what fields or methods I can use to get the error code. Thanks!
Aucun commentaire:
Enregistrer un commentaire