Giter Club home page Giter Club logo

Comments (6)

gordthompson avatar gordthompson commented on June 19, 2024 2

@githubmlai - Essentially, yes. You'd just keep calling nextset() until it returned False. The exception, if any, would either get thrown immediately or on one of the nextset() calls.

from pyodbc.

gordthompson avatar gordthompson commented on June 19, 2024

I notice that your stored procedure does not include

SET NOCOUNT ON;

as the first executable statement. Doing so could very likely avoid the issue.

from pyodbc.

githubmlai avatar githubmlai commented on June 19, 2024

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 proc

IF OBJECT_ID('dbo.spSwallowError') IS NULL
EXEC ('CREATE PROCEDURE dbo.spSwallowError AS SET NOCOUNT ON;');

GO

ALTER PROCEDURE dbo.spSwallowError
AS
BEGIN
SELECT 1;
SELECT 1 / 0;

 END;

from pyodbc.

gordthompson avatar gordthompson commented on June 19, 2024

@githubmlai - The SELECT 1; statement has already put a result set into the "pipeline" back to the client, so you won't see the exception until you call nextset() to try and retrieve the second result set:

>>> 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)')

from pyodbc.

githubmlai avatar githubmlai commented on June 19, 2024

Thanks! Any suggestions on how to guarantee pyodbc rethrows the error? Should I always fetch all the rows and then call next set repeatedly?

from pyodbc.

kumar1838 avatar kumar1838 commented on June 19, 2024

ERROR_NUMBER() AS ErrorNumber
ERROR_SEVERITY() AS ErrorSeverity
ERROR_STATE() AS ErrorState
ERROR_PROCEDURE() AS ErrorProcedure
ERROR_LINE() AS ErrorLine
ERROR_MESSAGE() AS ErrorMessage;

how to get these parameters in pyodbc using python? can anyone help me out please!!!!

from pyodbc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.