Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting compilation error while using BCP in VC++

Status
Not open for further replies.

kathyayini

Programmer
Aug 16, 2002
52
IN
My code is :
// BCP.cpp : Defines the initialization routines for the DLL.
//
#include "stdafx.h"
//#include "BCP.h"

#define DBNTWIN32
#include <stdio.h>
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>
#include <iostream.h> // iostream
#include <stdlib.h> // C run-time

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

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define DLLEXPORT _declspec(dllexport)

HINSTANCE g_hInstance;

BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call,LPVOID lpReserved)
{
g_hInstance=(HINSTANCE)hModule;
return TRUE;
}

extern &quot;C&quot; DLLEXPORT BOOL WINAPI BCP(char* lpszProvider, char* lpszDsn, char* lpszCatelog, char* lpszDBUid,char* lpszDBPwd, int Ino_of_threads, char* CSP_Names[],char* CParam[10][10],char* CType[10][10])
{
LOGINREC *login;
DBPROCESS *dbproc;
DBINT rowsread;

// Install error-handler and message-handler.
dberrhandle(ErrorHandler);
dbmsghandle(MessageHandler);

// Open a DBPROCESS.
login = dblogin();
DBSETLUSER(login, &quot;user&quot;);
DBSETLPWD(login, &quot;my_passwd&quot;);
DBSETLAPP(login, &quot;example&quot;);
BCP_SETL(login, TRUE);
dbproc = dbopen(login, &quot;my_server&quot;);

// Initialize bcp.
//if (bcp_init(dbproc, &quot;pubs..authors&quot;, &quot;authors.sav&quot;,(BYTE *)NULL, DB_OUT) == FAIL)
// exit(ERREXIT);

// Initialize bcp.
if (bcp_init(dbproc, &quot;comdb..address&quot;, &quot;address.add&quot;, &quot;addr.err&quot;,DB_IN) == FAIL)
exit(ERREXIT);


// Now, execute the bulk copy.
if (bcp_exec(dbproc, &rowsread) == FAIL)
{
printf(&quot;Incomplete bulk copy. Only %ld row%s copied.\n&quot;,rowsread, (rowsread == 1) ? &quot;&quot;: &quot;s&quot;);
}

return TRUE;
}

extern &quot;C&quot; int ErrorHandler (
PDBPROCESS pDbproc,
INT nSeverity,
INT nDBLibError,
INT nOSError,
LPCSTR pszDBLibError,
LPCSTR pszOSError)
{

if (nDBLibError == SQLEKBCO || nDBLibError == SQLEKBCI)
// handle &quot;1000 rows&quot; message
{
cout << pszDBLibError << endl;
return(INT_CANCEL); // don't quit. continue the process
}

// display DB-Library error information
cout << &quot;DB-Library Error &quot; << nDBLibError << &quot;: &quot; << 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 << &quot;Operating System Error &quot; << nOSError << &quot;: &quot; << pszOSError
<< endl;
}

return(INT_CANCEL);
}
}

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

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

cout << &quot; Message &quot; << lMessage << &quot;: &quot; << pszMessage;

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

cout << endl;

return(0);
}


while compiling i am getting error as follows:
--------------------Configuration: BCP - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
BCP.cpp
Linking...
Creating library Debug/BCP.lib and object Debug/BCP.exp
BCP.obj : error LNK2001: unresolved external symbol _bcp_exec
BCP.obj : error LNK2001: unresolved external symbol _bcp_init
BCP.obj : error LNK2001: unresolved external symbol _dbopen
BCP.obj : error LNK2001: unresolved external symbol _bcp_setl
BCP.obj : error LNK2001: unresolved external symbol _dbsetlname
BCP.obj : error LNK2001: unresolved external symbol _dblogin
BCP.obj : error LNK2001: unresolved external symbol _dbmsghandle
BCP.obj : error LNK2001: unresolved external symbol _dberrhandle
BCP.obj : error LNK2001: unresolved external symbol _dbdead
Debug/BCP.dll : fatal error LNK1120: 9 unresolved externals
Error executing link.exe.

BCP.dll - 10 error(s), 0 warning(s)

what could be the reason

waiting for the reply.
 
Hi,

You may need to add the Library in the link options

or

use TOOLS / OPTIONS / Directories

and add the path for the include and library files

Hope this Helps

DazzG

 
I included SQL Server library and include path in Tools->Options->Directories, But giving the same problem.

tools->options->directory->include file has these include paths:
D:\Microsoft Visual Studio\VC98\INCLUDE
D:\Microsoft Visual Studio\VC98\MFC\INCLUDE
D:\Microsoft Visual Studio\VC98\ATL\INCLUDE
C:\SYBASE\INCLUDE
C:\MSSQL7\DevTools\Lib

and tools->options->directory->library files has these library paths:
D:\Microsoft Visual Studio\VC98\LIB
D:\Microsoft Visual Studio\VC98\MFC\LIB
C:\SYBASE\LIB
C:\MSSQL7\DevTools\Include

what header file / lib file i have to include

waiting for the reply.
 
can anybody help me out for above mentioned problem.
its very urgent.
i tried all way (msdn solution for this error), but not getting the solution.

is there is any problem in below mentioned statements :
#define DBNTWIN32
#include <stdio.h>
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>
#include <iostream.h> // iostream
#include <stdlib.h> // C run-time

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

waiting for the reply.

 
You also need to add the .LIB filenames into the LINK options:

Project -> Settings -> Link
object / Library Modules.

This will stop the errors
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top