#include <windows.h>
#include <stdio.h>
#include <sql.h>
#include <sqlext.h>
main()
{
RETCODE rc;
HENV henv;
HDBC hdbc;
HSTMT hstmt;
char * dsn = "YourServer";
char * uid = "scott";
char * pwd = "tiger";
char * SQLStr = "{call TESTERR}";
SQLCHAR createProc[] = "CREATE OR REPLACE PROCEDURE TESTERR AS output_err_msg VARCHAR2(1000); raised_error_string "
"VARCHAR2(2); BEGIN raised_error_string := 'This assignment will raise an exception'; EXCEPTION WHEN "
"OTHERS THEN output_err_msg :='This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"This error message should contain 700 characters. "
"Errors!';raise_application_error(-20250, output_err_msg);END;";
// Variables for SQLGetDiagRec.
SQLCHAR sqlState[20];
SQLCHAR errorMsg[1000];
SQLSMALLINT errorMsgLen;
SQLINTEGER nativeError;
char szTemp[4096];
rc = SQLAllocEnv(&henv);
rc = SQLAllocConnect(henv, &hdbc);
rc = SQLConnect(hdbc, (unsigned char *)dsn,
SQL_NTS, (unsigned char *)uid,
SQL_NTS, (unsigned char *)pwd, SQL_NTS);
rc = SQLAllocHandle(SQL_HANDLE_STMT, hdbc,&hstmt);
// Create the stored procedure in Oracle.
rc = SQLExecDirect(hstmt, (unsigned char *)createProc, SQL_NTS);
SQLFreeStmt(hstmt, SQL_CLOSE);
// Run the newly created stored procedure.
rc = SQLExecDirect(hstmt, (unsigned char *)SQLStr, SQL_NTS);
// Retrieve the raised error message.
SQLGetDiagRec(SQL_HANDLE_STMT,hstmt,1,sqlState,
&nativeError,errorMsg,1000,&errorMsgLen);
// Display the size of the returned error message, and the message itself.
sprintf(szTemp, "Length=[%d] Text=[%s]", strlen((char*)errorMsg), errorMsg );
MessageBox(NULL, (LPSTR) szTemp,"ODBC Error Message",0);
SQLFreeStmt(hstmt, SQL_CLOSE);
SQLFreeStmt(hstmt, SQL_DROP);
SQLDisconnect(hdbc);
SQLFreeConnect(hdbc);
SQLFreeEnv(henv);
return(TRUE);
};