2

I need the script to monitor the sql server expiration from linux by python code and

In SQL output is coming but in linux, it gives the following error:

>>> cursor.execute("select loginproperty('tibbr_db','DaysUntilExpiration')")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('ODBC data type -150 is not supported.  Cannot read column .', 'HY000')
0

1 Answer 1

3

Explicitly cast the LOGINPROPERTY return value to an integer to work around the data type mapping problem by changing the query from this:

"select loginproperty('tibbr_db','DaysUntilExpiration')"

to this:

"select cast(loginproperty('tibbr_db','DaysUntilExpiration') as integer)"

The DaysUntilExpiration property in SQL Server should always return an integer, so you won't see any type errors with the explicit conversion.

ODBC type -150 looks like a SQL Server variant type, which pyodbc doesn't map to a python type.

Sign up to request clarification or add additional context in comments.

2 Comments

@user3311501 it is polite to mark this as the correct answer if indeed it fixed the problem. :)
If you're using FreeTDS, I'd recommend having a look at this driver instead if you're using SQL Server; it is much more feature complete and performant: microsoft.com/en-us/download/details.aspx?id=36437

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.