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')
Martijn Pieters
1.1m326 gold badges4.2k silver badges3.4k bronze badges
asked Nov 18, 2014 at 10:06
user3311501
1672 gold badges2 silver badges7 bronze badges
1 Answer 1
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.
answered Nov 18, 2014 at 14:06
Bryan
17.7k7 gold badges59 silver badges81 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
HelloW
@user3311501 it is polite to mark this as the correct answer if indeed it fixed the problem. :)
FlipperPA
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
lang-py