Microsoft KB Archive/237674

= INF: bcp_exec API Requires User Error Handler When Processing 1000 or More Records =

Article ID: 237674

Article Last Modified on 10/31/2003

-

APPLIES TO


 * Microsoft SQL Server 6.5 Standard Edition
 * Microsoft SQL Server 7.0 Standard Edition

-



This article was previously published under Q237674



SUMMARY
If the user does not provide an error handler routine, the bcp_exec dblib function generates an unhandled access violation when importing or exporting 1000 or more records and the program terminates abnormally.



MORE INFORMATION
For every 1000 records being processed, the bcp_exec function enters an internal error handler and sets the proper severity and message:

10049 - SQLEKBCO - Exported 1000 rows for each 1000 records it proceeds.

-or-

10051 - SQLEKBCI - 1000 rows copied to SQL Server

If the user does not provide a message handler routine for the preceding error message, bcp_exec causes an unhandled access violation.

A sample error handler routine can be implemented as follow:
 * 1) include "stdafx.h"
 * 2) include           // iostream
 * 3) include             // C run-time
 * 4) include "windows.h"
 * 5) include "SQLfront.h"
 * 6) include "sqldb.h"

extern "C" int ErrorHandler (PDBPROCESS, INT, INT, INT, LPCSTR, LPCSTR); extern "C" int MessageHandler (PDBPROCESS, DBINT, INT, INT, LPCSTR, LPCSTR, LPCSTR, DBUSMALLINT);

int main(int argc, char* argv[]) {

PLOGINREC  login;     // The login information. login = dblogin ; DBSETLUSER(login, "sa"); DBSETLPWD(login, ""); DBSETLAPP(login, ""); BCP_SETL(login, TRUE); PDBPROCESS m_dbproc = dbopen (login, "serv_name");

// install error and message handlers dberrhandle (ErrorHandler); dbmsghandle (MessageHandler); :        : }

extern "C" int ErrorHandler (   PDBPROCESS pDbproc,    INT nSeverity,    INT nDBLibError,    INT nOSError,    LPCSTR pszDBLibError,    LPCSTR pszOSError) {  if (nDBLibError == SQLEKBCO || nDBLibError == SQLEKBCI) // handle "1000 rows" message {       cout << pszDBLibError << endl; return(INT_CANCEL);      // don't quit. continue the process }

// display DB-Library error information cout << "DB-Library Error " << nDBLibError << ": " << pszDBLibError << endl;

if ((pDbproc == NULL) || (DBDEAD(pDbproc))) {       return(INT_EXIT); }   else {       if (nOSError != DBNOERR) {           // this DB-Library error was caused by an operating system // error, so display OS error information cout << "Operating System Error " << nOSError << ": " << pszOSError << endl; }

return(INT_CANCEL); } }

extern "C" int MessageHandler (   PDBPROCESS pDbproc,    DBINT lMessage,    INT nState,    INT nSeverity,    LPCSTR pszMessage,    LPCSTR pszServer,    LPCSTR pszProcedure,    DBUSMALLINT usLine) {   // display SQL Server message information cout << "SQL Server";

if (pszServer != NULL) {       if (*pszServer != '\0') {           cout << " '" << pszServer << "'"; }   }

cout << " Message " << lMessage << ": " << pszMessage;

if (usLine != 0) {       cout << " (Concerning line " << usLine;        if (pszProcedure != NULL)        {            cout << " of stored procedure '" << pszProcedure << "'";        }        cout << ")"; }

cout << endl;

return(0); }

Keywords: kbinfo kbcodesnippet KB237674

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.