August 11, 2004 at 2:17 am
Would anyone know how to fix this error?
Function: bcp_init
SQLSTATE: HY000
Native Error: 0
Diagnostic: [Microsoft][ODBC SQL Server Driver]Unable to open BCP error-file
I checked the microsoft website and it said that the error file might be non existent or in use. How can i know what is the error file that is being called by bcp_init?
Thanks,
August 16, 2004 at 8:00 am
This was removed by the editor as SPAM
February 13, 2016 at 6:17 am
Try this code which worked in my case.
#include <stdio.h>
#include <windows.h>
#include <sql.h>
#include <sqlext.h>
//#include <odbcss.h>
#include ".\\sqlncli.h"
SQLHENV henv = SQL_NULL_HENV;
HDBC hdbc1 = SQL_NULL_HDBC;
typedef RETCODE (CALLBACK* SQL_API bcp_initA123 )(HDBC, LPCSTR, LPCSTR, LPCSTR, INT);
typedef RETCODE (CALLBACK* SQL_API bcp_readfmtA123 )(HDBC, LPCSTR);
typedef RETCODE (CALLBACK* SQL_API bcp_exec123 )(HDBC, LPDBINT);
void Cleanup() {
if (hdbc1 != SQL_NULL_HDBC) {
SQLDisconnect(hdbc1);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc1);
}
if (henv != SQL_NULL_HENV)
SQLFreeHandle(SQL_HANDLE_ENV, henv);
}
int main() {
RETCODE retcode;
SDWORD cRows;
// Allocate the ODBC environment and save handle.
retcode = SQLAllocHandle (SQL_HANDLE_ENV, NULL, &henv);
if ( (retcode != SQL_SUCCESS_WITH_INFO) && (retcode != SQL_SUCCESS)) {
printf("SQLAllocHandle(Env) Failed");
Cleanup();
return(9);
}
// Notify ODBC that this is an ODBC 3.0 app.
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER);
if ( (retcode != SQL_SUCCESS_WITH_INFO) && (retcode != SQL_SUCCESS)) {
printf("SQLSetEnvAttr(ODBC version) Failed");
Cleanup();
return(9);
}
// Allocate ODBC connection handle, set BCP mode, and connect.
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc1);
if ( (retcode != SQL_SUCCESS_WITH_INFO) && (retcode != SQL_SUCCESS)) {
printf("SQLAllocHandle(hdbc1) Failed");
Cleanup();
return(9);
}
retcode = SQLSetConnectAttr(hdbc1, SQL_COPT_SS_BCP, (void *)SQL_BCP_ON, SQL_IS_INTEGER);
if ( (retcode != SQL_SUCCESS_WITH_INFO) && (retcode != SQL_SUCCESS)) {
printf("SQLSetConnectAttr(hdbc1) Failed");
Cleanup();
return(9);
}
// Sample uses Integrated Security. Create SQL Server DSN using Windows NT authentication.
retcode = SQLConnect(hdbc1, (UCHAR*)"Test", SQL_NTS, (UCHAR*)"", SQL_NTS, (UCHAR*)"", SQL_NTS);
if ( (retcode != SQL_SUCCESS) && (retcode != SQL_SUCCESS_WITH_INFO) ) {
printf("SQLConnect() Failed");
Cleanup();
return(9);
}
//////////////////////////////////////////////////////////////////
HDBC hdbc12 = SQL_NULL_HDBC;
HINSTANCE dllHandle = LoadLibrary("sqlncli11.dll");
//HINSTANCE dllHandle = LoadLibrary("odbcbcp.dll");
if (NULL != dllHandle)
{
bcp_initA123 procInit =(bcp_initA123 )GetProcAddress(dllHandle,"bcp_initA");
retcode = procInit(hdbc1, "swetha_user.dbo.BCPDate", "BCPODBC.bcp", NULL, DB_IN);
if(retcode ==1)
{
bcp_readfmtA123 procreadFmt =(bcp_readfmtA123)GetProcAddress(dllHandle,"bcp_readfmtA");
retcode= procreadFmt(hdbc1, ".\\BCPFMT.fmt");
if(retcode ==1)
{
bcp_exec123 bcpexecproc =(bcp_exec123 )GetProcAddress(dllHandle,"bcp_exec");
retcode = bcpexecproc(hdbc1, &cRows);
}
}
}
DWORD dw1=GetLastError();
FreeLibrary(dllHandle);
Cleanup();
return 0;
}
February 13, 2016 at 7:29 am
Note original thread is over 11 years old.
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply