1

I'm almost finished with one script that will check a table and email the result of this one. Although I'm getting this error.

No results.  Previous SQL was not a query.

This is what my script looks like.

import os
import sys
import pyodbc
import smtplib

# Set up mail info
FROM = "[email protected]"
TO = ["[email protected]"] # must be a list
TEXT = "Dialer import status "
SUBJECT = "Dialer import status"

#Defining variables for script 
try:
    cnxn = pyodbc.connect('DRIVER={SQL  Server}
    ;SERVER=sesrv413;DATABASE=Maintenance;Trusted_Connection=yes')
    cursor = cnxn.cursor()
    query = "Select status from dialer_import_status"
    rows =  cursor.fetchall()
    for row in rows:
    TEXT = TEXT + str(row.status)

except:
# Send the mail
  server = smtplib.SMTP("email.intrum.net",25)
  message = "From:%s \nTo:%s \nSubject:%s 
  \n\n%s\n" %(FROM, ", ".join(TO),  SUBJECT, TEXT)
  server = smtplib.SMTP("email.company.net",25)
  server.sendmail(FROM, TO, message)
  server.quit()
  raise

Has anyone experience similar issues before? And how did you solve it?

Cheers

1 Answer 1

2

No query has been executed, because you forgot to call cursor.execute(query) before cursor.fetchall().

Sign up to request clarification or add additional context in comments.

2 Comments

do I need to import something to use execute? like Import pyodbc etc. I'm new to shell scripting
no, just call the method on the cursor object. I fixed my code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.