Unix Technical Forum

ODBC and stored procedure

This is a discussion on ODBC and stored procedure within the MS SQL ODBC forums, part of the Microsoft SQL Server category; --> Let's suppose we have an stored procedure that make an insert in a table. That insert fail (primary key ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > MS SQL ODBC

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 07:32 PM
Ionut Ceausu
 
Posts: n/a
Default ODBC and stored procedure

Let's suppose we have an stored procedure that make an insert in a
table. That insert fail (primary key constrain). This stored procedure is
called from C using ODBC with
hr = SQLExecuteDirect(hstmt,L"{call MyProc }",SQL_NTS)

If the insert from MyProc fail, i will obtain an hr != S_OK (and from here
with GetDiagRec I will obtain the error) only if in stored procedure I put
SET NOCOUNT ON. How do I obtain the error without putting SET NOCOUNT ON? I
suppose this can be done (ADO can do this)
Thanks.



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 07:32 PM
Brannon Jones [MS]
 
Posts: n/a
Default Re: ODBC and stored procedure

After your call to SQLExecDirect() add a call to SQLMoreResults() and check
the return code of SQLMoreResults(). That *should* work. You probably want
to call SQLMoreResults() in a loop until it returns SQL_ERROR or
SQL_NO_DATA.

BTW- ODBC does not use HRESULTS (as you are using below). ODBC uses the
SQLRETURN type. If your example, it just so happens that SQL_SUCCESS and
S_OK are both #define'd as ZERO.

There are only a few interesting error codes in ODBC:

0 SQL_SUCCESS
1 SQL_SUCCESS_WITH_INFO (should examine the diag records to see
what info was posted to the handle)
100 SQL_NO_DATA (no more results...)
-1 SQL_ERROR (generic error, need to examine the diag records to
see what error was posted to the handle).

The TRUE error codes in ODBC are stored as SQL States (in the diag records).
The ODBC reference material documents the different states and what they
mean (see Appendix A).

Brannon

"Ionut Ceausu" <shadow_s@softhome.net.NO_SPAM> wrote in message
news:uz1w%23YXmDHA.360@TK2MSFTNGP12.phx.gbl...
> Let's suppose we have an stored procedure that make an insert in a
> table. That insert fail (primary key constrain). This stored procedure is
> called from C using ODBC with
> hr = SQLExecuteDirect(hstmt,L"{call MyProc }",SQL_NTS)
>
> If the insert from MyProc fail, i will obtain an hr != S_OK (and from here
> with GetDiagRec I will obtain the error) only if in stored procedure I put
> SET NOCOUNT ON. How do I obtain the error without putting SET NOCOUNT ON?

I
> suppose this can be done (ADO can do this)
> Thanks.
>
>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 07:33 PM
Ionut Ceausu
 
Posts: n/a
Default Re: ODBC and stored procedure

Thanks....that really work.
Ionut.


"Brannon Jones [MS]" <branjo@nospam.microsoft.com> wrote in message
news:eQ0xmlcmDHA.2536@tk2msftngp13.phx.gbl...
> After your call to SQLExecDirect() add a call to SQLMoreResults() and

check
> the return code of SQLMoreResults(). That *should* work. You probably

want
> to call SQLMoreResults() in a loop until it returns SQL_ERROR or
> SQL_NO_DATA.
>
> BTW- ODBC does not use HRESULTS (as you are using below). ODBC uses the
> SQLRETURN type. If your example, it just so happens that SQL_SUCCESS and
> S_OK are both #define'd as ZERO.
>
> There are only a few interesting error codes in ODBC:
>
> 0 SQL_SUCCESS
> 1 SQL_SUCCESS_WITH_INFO (should examine the diag records to see
> what info was posted to the handle)
> 100 SQL_NO_DATA (no more results...)
> -1 SQL_ERROR (generic error, need to examine the diag records

to
> see what error was posted to the handle).
>
> The TRUE error codes in ODBC are stored as SQL States (in the diag

records).
> The ODBC reference material documents the different states and what they
> mean (see Appendix A).
>
> Brannon
>
> "Ionut Ceausu" <shadow_s@softhome.net.NO_SPAM> wrote in message
> news:uz1w%23YXmDHA.360@TK2MSFTNGP12.phx.gbl...
> > Let's suppose we have an stored procedure that make an insert in a
> > table. That insert fail (primary key constrain). This stored procedure

is
> > called from C using ODBC with
> > hr = SQLExecuteDirect(hstmt,L"{call MyProc }",SQL_NTS)
> >
> > If the insert from MyProc fail, i will obtain an hr != S_OK (and from

here
> > with GetDiagRec I will obtain the error) only if in stored procedure I

put
> > SET NOCOUNT ON. How do I obtain the error without putting SET NOCOUNT

ON?
> I
> > suppose this can be done (ADO can do this)
> > Thanks.
> >
> >
> >

>
>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:28 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com