question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Retrieving informational messages returned by server

See original GitHub issue

(Inspired by this Stack Overflow question.)

Is there a way that we can retrieve informational messages sent by the server, for example, those produced by a PRINT statement in a T-SQL stored procedure?

For a test SP

USE [myDb]
GO

/****** Object:  StoredProcedure [dbo].[PrintTest]    Script Date: 2018-12-14 10:59:12 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		gord
-- Create date: 
-- Description:	
-- =============================================
ALTER PROCEDURE [dbo].[PrintTest] 
AS
BEGIN
    SET NOCOUNT ON;
    PRINT 'no es bueno';
END

GO

the message does appear in the ODBC trace

main            1c0c-18b0	ENTER SQLExecDirectW 
        HSTMT               0x000000000040DFA0
        WCHAR *             0x0000000002F52830 [      18] "EXEC dbo.PrintTest"
        SDWORD                    18

main            1c0c-18b0	EXIT  SQLExecDirectW  with return code 1 (SQL_SUCCESS_WITH_INFO)
        HSTMT               0x000000000040DFA0
        WCHAR *             0x0000000002F52830 [      18] "EXEC dbo.PrintTest"
        SDWORD                    18

        DIAG [01000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]no es bueno (0) 

but is there a way we can retrieve it in our Python script?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
matthewgdvcommented, Jul 2, 2019

Is this still being looked at? This would be dead useful for me, as my organization uses stored procs all over the place that feed back information about the success/failure state of the subprocedures they call as print statements rather than raising errors, since an error would kill the whole thing. I currently have no way of finding out what a proc actually did when I call it using pyodbc.

5reactions
jerryclcommented, Apr 11, 2020

I agree this would be a great feature.

PEP-249 specifies an Optional DB API Extension, of Cursor.messages, which would contain a list of tuples (exception class, exception value). This is a bit different from the list of tuples [(SqlState,Msg,NativeError)] proposed above, but the SqlState and the NativeError could be put into the exception class.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why am I getting the message "Contacting the server for ...
The message remains open the entire time Microsoft 365 is trying to contact the remote location. Office message: Contacting the server for more...
Read more >
Informational messages returned with WCF involved
I think you basically have two proper ways of doing this: add a InfoMessage : string field to all your DataContracts, which can...
Read more >
Return Backend Server original error messages - IBM
When WebSEAL is unable to process a request from a client, WebSEAL returns an HTML error message page to the client. The error...
Read more >
HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >
Status codes in HTTP - W3C
Server has received the request but there is no information to send back, and the client should stay in the same document view....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found