Python Forum

Full Version: Execute DBCC CHECKDB from python script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
Actually I resolved my issue by adding parameter tableresults

Thanks