all groups > sql server odbc > october 2003 >
You're in the

sql server odbc

group:

ODBC and stored procedure


Re: ODBC and stored procedure Brannon Jones [MS]
10/23/2003 5:54:37 PM
sql server odbc:
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

[quoted text, click to view]

ODBC and stored procedure Ionut Ceausu
10/23/2003 5:59:18 PM
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.


Re: ODBC and stored procedure Ionut Ceausu
10/24/2003 10:00:18 AM
Thanks....that really work.
Ionut.


[quoted text, click to view]

AddThis Social Bookmark Button