New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Losing exceptions generated within Stored Procedures in MS SQL Server 2012 #69
Comments
I notice that your stored procedure does not include
as the first executable statement. Doing so could very likely avoid the issue. |
I'm experiencing a similar issue. When pyodbc executes the following stored procedure, the error (divide by 0) is not caught Here is the stored procIF OBJECT_ID('dbo.spSwallowError') IS NULL GO ALTER PROCEDURE dbo.spSwallowError
|
@githubmlai - The >>> import pyodbc
>>> conn = pyodbc.connect("DSN=myDb;")
>>> crsr = conn.cursor()
>>> crsr.execute("{CALL dbo.spSwallowError}")
<pyodbc.Cursor object at 0x03041218>
>>> rows = crsr.fetchall()
>>> rows
[(1, )]
>>> crsr.nextset()
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
crsr.nextset()
pyodbc.DataError: ('22012', '[22012] [Microsoft][SQL Server Native Client 10.0][SQL Server]Divide by zero error encountered. (8134) (SQLMoreResults)') |
Thanks! Any suggestions on how to guarantee pyodbc rethrows the error? Should I always fetch all the rows and then call next set repeatedly? |
@githubmlai - Essentially, yes. You'd just keep calling |
ERROR_NUMBER() AS ErrorNumber how to get these parameters in pyodbc using python? can anyone help me out please!!!! |
Hi, I have a strange one, whereby I seem to be losing exceptions from MS SQL Server.
When I invoke a stored procedure, using the 'ProofOfPyodbcError.py' (attached), I receive exceptions up until I do some sort of Update DDL in the Stored Procedure.
Prior to the Insert/Update/Delete, I can receive exceptions.
The ProofOfPyodbcError.py script has hard coded Database connection string, so it will need to be tweaked if you wish to run it.
After the Insert/Update/Delete, it doesn't matter what I do, no exceptions are received by the python code.
The attached Proof_Of_Error_DDL.sql will establish a test table and stored procedure, although, the script does have a hard coded Database name in it.
The ODBC settings are done using C:\Windows\SysWOW64\odbcad32.exe to create a "System DSN", which is used in the Database connection string.
Am I simply doing something wrong with my Python code or is there something deeper?
I originally hit this whilst using SQLAlchemy but have narrowed it down to pyodbc.
Environment:
Suggestions more than welcomed!
DDL to create Stored Procedure and Table used by Stored Procedure.
Proof to show that SQL Server does raise exceptions when expected, using the execution mechanism as captured by SQL Trace.
Python code using pyodbc to invoke the above stored procedure, expecting the same results as manually executing the stored proc in SQL Server Management Studio
The text was updated successfully, but these errors were encountered: