Installs a user function to handle SQL Server messages.
DBMSGHANDLE_PROC dbmsghandle (DBMSGHANDLE_PROC handler );
where
The line number pertains to the nesting level at which the message was generated. For instance, if a command batch executes stored procedure A, which then calls stored procedure B, and a message is generated at line 3 of B, then the value of line becomes 3.
If no line number is associated with the message, line becomes 0. Circumstances that can generate messages without line numbers include a login error or a call to a remote procedure (through dbrpcsend) to a stored procedure that doesn't exist.
line is optional.
The message handler must return a value of 0 to DB-Library.
A pointer to the previously installed message handler. This can be NULL.
This function installs a message-handling function that you supply. When DB-Library receives a SQL Server error or informational message, it immediately calls this message handler. You must install a message handler to handle SQL Server messages.
Since the message handler is a call-back function, special considerations are required when compiling these functions under the Windows operating system. For more information, see Building Applications.
Note The srvname, procname, and line parameters are optional, and compatibility with previous versions of SQL Server is maintained through the cdecl parameter declaration convention.
The following example shows a typical message-handling function:
#include <sqlfront.h> #include <sqldb.h> int msg_handler(dbproc, msgno, msgstate, severity, msgtext, srvname, procname, line) DBPROCESS *dbproc; DBINT msgno; int msgstate; int severity; char *msgtext; char *srvname; char *procname; DBUSMALLINT line; { printf("SQL Server message %ld, state %d, " "severity %d:\n\t%s\n", msgno, msgstate, severity, msgtext); if (strlen(srvname)==0) printf ("Server '%s', ", srvname); if (strlen(procname)==0) printf ("Procedure '%s', ", procname); if (line==0) printf ("Line %d", line); printf("\n\t%s\n", msgtext); return(0); }