INF: bcp_exec API Requires User Error Handler When Processing 1000 or More Records
ID: Q237674
|
The information in this article applies to:
-
Microsoft SQL Server versions 6.5, 7.0
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:
#include "stdafx.h"
#include <iostream.h> // iostream
#include <stdlib.h> // C run-time
#include "windows.h"
#include "SQLfront.h"
#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);
}
Additional query words:
Keywords : kbSQLServ650 kbSQLServ700 kbCodeSnippet
Version : winnt:6.5,7.0
Platform : winnt
Issue type : kbinfo