Python Forum
Execute DBCC CHECKDB from python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Execute DBCC CHECKDB from python script
#1
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
Reply
#2
Actually I resolved my issue by adding parameter tableresults

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is there a *.bat DOS batch script to *.py Python Script converter? pstein 3 3,009 Jun-29-2023, 11:57 AM
Last Post: gologica
  How To Set Up And Execute A Python File knight2000 4 1,825 May-31-2022, 10:02 AM
Last Post: Larz60+
  execute python script guy7200 1 1,574 Oct-25-2021, 09:55 PM
Last Post: Axel_Erfurt
  Possible to execute a python script before log off/shutdown with input commands? Kaltex 1 2,235 May-18-2021, 06:31 AM
Last Post: Skaperen
  Using python to execute app or cmd that requires admin credentials thewolf 0 2,078 Mar-05-2021, 08:15 PM
Last Post: thewolf
  Execute full script samuelbachorik 0 1,514 Aug-06-2020, 08:09 PM
Last Post: samuelbachorik
  How to kill a bash script running as root from a python script? jc_lafleur 4 5,790 Jun-26-2020, 10:50 PM
Last Post: jc_lafleur
  crontab on RHEL7 not calling python script wrapped in shell script benthomson 1 2,248 May-28-2020, 05:27 PM
Last Post: micseydel
  Trying to write and execute first Python script garvind25 3 2,847 May-23-2020, 07:36 PM
Last Post: garvind25
  Execute script in IDLE with parameters Pavel_47 11 7,152 Mar-14-2020, 05:41 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020