Python Forum
Execute DBCC CHECKDB from python script - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Execute DBCC CHECKDB from python script (/thread-28956.html)



Execute DBCC CHECKDB from python script - susja - Aug-11-2020

I have to run this query from inside the python script using pyodbc (python 3):

DBCC CHECKDB ('database_name') WITH ESTIMATEONLY
In code I have the following:

query = '''
DBCC CHECKDB ('database_name') WITH ESTIMATEONLY
'''
curs.execute(query)
resultSet = curs.fetchall()
I've got the error: resultSet = curs.fetchall() pyodbc.ProgrammingError: No results. Previous SQL was not a query.

Note: In case I have any 'select ..' query it works fine. It looks to me that pyodbc can't handle DBCC CHECKDB .. statement

I noticed that when I run this statement from SQL client the output goes into Tab 'Messages' while output from 'select' statements go into Tab 'Result Set'. Sounds that 'output' does not have information from 'Messages'. Maybe query should be modified to get result from 'Messages' or etc.?

Question: how could I run it from inside the python script?

Thanks


RE: Execute DBCC CHECKDB from python script - susja - Aug-12-2020

Actually I resolved my issue by adding parameter tableresults

Thanks