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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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. |
| |||
| 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. > > > |
| ||||
| 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. > > > > > > > > |