title: PyODBC Error:No results. Previous SQL was not a query Using 'SET NOCOUNT ON'
body: <p>I know this question has been asked before, I have already looked up <a href="https://stackoverflow.com/questions/7753830/mssql2008-pyodbc-previous-sql-was-not-a-query">here</a>. I have used SET NOCOUNT ON in the SQL Query still it gives me the error, Decided to post my code here so that it can be reviewed well. Can anyone help me with this?</p>
  
  <pre><code>    @property
      def sqlquery(self):
          retry_flag = True
          retry_count = 0
          conn = pyodbc.connect("Driver={SQL Server};"
                                "Server=server1;"
                                "Database=db1;"
                                "Trusted_Connection=yes;")
          cursor = conn.cursor()
          while retry_flag and retry_count &lt; 10:
              try:
                  cursor.execute('''
          SET NOCOUNT ON;
          SELECT * FROM xx.y
          WHERE y = '%s'
          AND a = '%s'
          AND b = '%s'
          AND c = '%s'
          AND d = '%s' ''' % (1stplaceholder, 2nd, 3rd, 4th, 5th))
                  retry_flag = False
              except:
                  print("Retry after 1 sec")
                  retry_count = retry_count + 1
                  time.sleep(1)
          for row in cursor:
              if cursor is None:
                  return False
              else:
                  return row[19]
          conn.close()
  </code></pre>
  
  <p>I have also referred to this <a href="https://stackoverflow.com/questions/41473137/pyodbc-how-to-retry-to-recover-from-transient-errors">question</a> as I was getting Error <strong>pyodbc.Error: ('01000', '[01000] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionRead (recv()). (10054) (SQLExecDirectW)')</strong> </p>
  
  <p>I have 3 sql queries similar to this in my script and after running almost 10k iterations it gave me an error <strong>pyodbc.ProgrammingError: No results.  Previous SQL was not a query.</strong> So, the SQL queries are perfectly fine and so is the connection to database.</p>