Bcp_sendrow Causing Unhandled Exception (0xC0000005: Access Violation Reading Location 0x00000123)
Jun 24, 2007Hi,
Background:
This could be a simple C++ issue as I am not that familiar with the language. I am trying to prototype a small program to test the performance of inserting data using the BCP interface. I want to BCP data that my program generates and passes via program variables.
I have narrowed the issue down to a sprintf call. Following are two variations of the code - one that works and one that does not. The error happens when I try to execute the bcp_sendrow() call.
What is the appropriate way to create / send string data to the BCP interface. Any good examples available? I have created the following from the BulkCopyFromVariables example on the Microsoft SQL Server downloads site.
Thanks in advance, Kerry
---- Works ----
Code Snippet
for(idx=1; idx<=5; idx++){
//sprintf(k1, "%d", idx); //does not work...
sprintf(k1, "oo"); //works....
if ( (SendRet = bcp_sendrow(hdbc1) ) != SUCCEED ) {
printf("bcp_sendrow(hdbc1) Failed
");
Cleanup();
return(9);
}
}
--- Causes Access Violation ----
Code Snippet
for(idx=1; idx<=5; idx++){
sprintf(k1, "%d", idx); //does not work...
//sprintf(k1, "oo"); //works....
if ( (SendRet = bcp_sendrow(hdbc1) ) != SUCCEED ) {
printf("bcp_sendrow(hdbc1) Failed
");
Cleanup();
return(9);
}
}
--- Additional information ---
---------------------------
Target Table Definition
---------------------------
Code SnippetCREATE TABLE PtTest(
[ID] [int] IDENTITY(1,1) NOT NULL,
[PtID] [int] NOT NULL,
[ParamID] [nchar](10) NULL DEFAULT ((200)), --Above example trying to insert data here via k1 variable...
[ParamValue] [nchar](10) NULL DEFAULT ((200)),
[InsDate] [datetime] NULL DEFAULT (getdate()),
)
----------------------------
-----------------
Bind statements
-----------------
Code Snippet
int idx;
char k1[5];
char *terminator = "