title: pyodbc doesn't report sql server error
body: <p>I have an issue where pyodbc doesn't capture errors returned from stored procedure. My actual stored proc does a lot of stuff but for the purpose of demonstrating the error I created a simple proc and associated python code. Relevant code is below:</p>
  
  <p><strong>Stored Procedure:</strong></p>
  
  <pre><code>CREATE PROCEDURE [dbo].[testErrors]
      -- Add the parameters for the stored procedure here
  
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      -- Insert statements for procedure here
      insert into Parameter(Name, Units, DataType) values (null, null, null)
  END
  
  GO
  </code></pre>
  
  <p><strong>Python code:</strong></p>
  
  <pre><code>import pyodbc
  connectString = "DRIVER={SQL Server};SERVER=%s;DATABASE=%s;UID=%s;PWD=%s" % (r'srvr', r'mydb', r'usr', r'pwd')
  cnxn = pyodbc.connect(connectString)
  cnxn.autocommit = True
  cursor = cnxn.cursor()
  cursor.execute("exec testErrors")
  cursor.close()
  </code></pre>
  
  <p><strong>Error I get as expected:</strong></p>
  
  <pre><code> cursor.execute("exec testErrors")
  pyodbc.IntegrityError: ('23000', "[23000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert the value NULL into column 'Name', table 'Parametrics.dbo.Parameter'; column does not allow nulls. INSERT fails. (515) (SQLExecDirectW); [01000] [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated. (3621)")
  </code></pre>
  
  <p>However when I modified my stored procedure to include a select statement the error no longer comes back to my python code. Python code exits as if no error has occurred.</p>
  
  <p><strong>Updated Stored Procedure:</strong></p>
  
  <pre><code>CREATE PROCEDURE [dbo].[testErrors]
      -- Add the parameters for the stored procedure here
  
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
      select 108
      -- Insert statements for procedure here
      insert into Parameter(Name, Units, DataType) values (null, null, null)
  END
  
  GO
  </code></pre>
  
  <p>It seems pyodbc doesn't see the error when there are interleaving result records through select statements. What is the issue here and is there a way to overcome this issue?</p>
  
  <p><strong>EDIT:</strong> I tried this with pymssql and see the same behavior</p>