|
-
January 20th, 2007, 02:20 PM
#1
"Multiple-step OLE DB ... errors" on ADO PutValue
[VC++ 6.0, SQL Server]
I get the this error when I execute the last line of the following code:
"Multiple-step OLE DB operation generated errors. Check each OLE DB value, if available. No work was done."
Code:
CString csState = "MA";
BYTE* bt = new BYTE [256]
for (int i = 0; i < 256; i++) //my initialization for testing
{
bt[i] = i + 1;
}
BSTR bstrBuff = SysAllocStringLen((LPOLESTR)bt,256);
pRst->Fields->GetItem("state")->Value = (_bstr_t) csState;
pRst->Fields->GetItem("data")->Value = bstrBuff;
The assignment of 'state' [varchar(2)] is OK. When csState has 3 characters, I get the same error.
A recurring theme in the forum(s) for this error around this kind of operation is:
the value is not suitable for the field to store.
The database field 'data' is declared as varchar(600). I also tried varbinary(600).
So, I am at a loss for an explanation.
Thanks for any thoughts,
jim
EDIT: corrected the bug in my code example.
Perhaps a buggy example doesn't warrant a response.
I am completely stalled on this.
Does any body have an idea?
Thanks,
jim
Last edited by joleary; January 28th, 2007 at 10:42 AM.
-
January 28th, 2007, 07:37 PM
#2
Re: "Multiple-step OLE DB ... errors" on ADO PutValue
Here is some additional info:
Based on some further research, I've updated my code sample (including bug fix) as follows:
Code:
BYTE* bt = new BYTE [256];
for (int j = 0; j < 256; j++) //my initialization for testing
{
bt[j] = j + 1;
}
BSTR bstrBuff = SysAllocStringByteLen((LPCSTR)bt,256);
_bstr_t bstrt(bstrBuff );
int bstrLen = bstrt.length(); //this is 128
pRst->Fields->GetItem("TData")->Value = bstrt;
Also, here's the definition of the 'TData' field
[TData] [varchar] (600) NULL
But I still get the error:
"Error number: 0x80040e21
Multiple-step OLE DB operation generated errors."
The field accepts NULLs if for some reason bstrt was NULL. The field should have plenty of space for the BSTR of size 128. [And as I mentioned before I also tried varbinary(600).]
I've also looked at the memory of bstrBuff and bstrt in the debugger and they both seem like well formed BSTRs with the expected initial values.
Can anybody give me a clue as to why I'm still getting this message? I'm really brick-walled here.
Humble thanks,
jim
-
February 9th, 2007, 11:40 AM
#3
Re: "Multiple-step OLE DB ... errors" on ADO PutValue
For anyone who may be interested in the resolution to this problem:
I received from invaluable help from Krzemo in the CodeGuru Database forum.
I was told that although BSTR can contain binary values, it cannot be used to store binary values into a database. And that seems to have been the reason for the error message.
I was advised to convert my BYTE* array to SAFEARRAY and use the SAFEARRAY to write to/read from the database.
To convert to/from BYTE* and SAFEARRAY, I adapted code from the sample in
http://www.codeproject.com/database/...select=1608797
All seems to be well.
jim
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|