user3311501
user3311501

Reputation: 167

cursor.execute in python for SQL

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')

Upvotes: 2

Views: 1216

Answers (1)

Bryan
Bryan

Reputation: 17703

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.

Upvotes: 3

Related Questions