IRowsetChange::InsertRow Error DBSTATUS_E_CANTCONVERTVALUE only on x64 builds

rvandam 0 Reputation points
2025-05-16T03:46:05.48+00:00

I have created a function that inserts data into a MSSQL 2022 Database Table. The function works fine when I build it using win32\release, but fails when I use x64\release. I received Error DBSTATUS_E_CANTCONVERTVALUE for the first column which is a string (varchar or nvarchar). I tried using both to see if it made a difference. If I set the data to NULL (DBSTATUS_S_ISNULL) it will insert the record with a NULL value.

I have the current version of MSOLEDBSQL driver installed as well as the most recent version of VC++ Redistrib (both x64 & 32 versions installed).

There is nothing special about the text used. Most of it under 128 characters, The varchar size is 2048. Compiled as a 32 bit win app it runs perfectly, & inserted about 50k rows. Complied as x64 it fails on every row.

typedef struct {
	char				sValue[2048]; //sValue[128];
	ULONG				m_status[2];
	ULONG				m_length[2];
} DBTblStruct;
...

DBTblStruct 						 dbRow;
IAccessor						    *pIRow;
IRowsetUpdate						*spRowsetUpdate;
HACCESSOR							 hAccessor;	
HROW							     hRow[1], *phRow;

 
StringW = L"Test String";

DBBindings[0].bPrecision = 0;
DBBindings[0].bScale = 0;
DBBindings[0].dwFlags = 0;
DBBindings[0].dwPart = DBPART_VALUE | DBPART_STATUS | DBPART_LENGTH;
DBBindings[0].eParamIO = DBPARAMIO_NOTPARAM;
DBBindings[0].iOrdinal = 1;
DBBindings[0].obLength = offsetof(DBTblStruct, m_length[0]);
DBBindings[0].obStatus = offsetof(DBTblStruct, m_status[0]);
DBBindings[0].pBindExt = NULL;
DBBindings[0].pObject = NULL;
DBBindings[0].pTypeInfo = NULL;
DBBindings[0].dwMemOwner = DBMEMOWNER_CLIENTOWNED;
DBBindings[0].cbMaxLen = sizeof(dbRow.StringW);
DBBindings[0].obValue = offsetof(DBTblStruct, StringW);
DBBindings[0].wType = DBTYPE_WSTR;
ZeroMemory(&dbRow.StringW, sizeof(dbRow.StringW));
wcsncpy(dbRow.StringW, StringW, wcslen(StringW));
dbRow.m_status[0] = DBSTATUS_S_OK;

hr = pIRow->CreateAccessor(DBACCESSOR_ROWDATA,  //dwAccessorFlags
                           1,                   //ULONG cBindings
                           DBBindings,          //rgBindings[]          
                           sizeof(DBTblStruct), //cbRowSize,
                          &hAccessor,           //phAccessor
                           RowBindStatus );     //rgStatus[]
//Always returns S_OK - No errors
hr = spRowsetUpdate->InsertRow(DB_NULL_HCHAPTER,        //hReserved
                               hAccessor,               //hAccessor
                              &dbRow,                   //pData
                               phRow);                  //phRow
//Always returns 0x80040E21 
//m_status[0] is set to  DBSTATUS_E_CANTCONVERTVALUE

I've tried both ansi (DBTYPE_STR - varchar) & unicode (DBTYPE_WSTR - nvarchar). Tried using just one character in the string & it fails with DBSTATUS_E_CANTCONVERTVALUE. A test SQL table with just one column was used to rule out issues with other columns. if I use a DBTYPE_UI4 for the column it will insert, but not for any string type columns (varchar, nvarchar, char, nchar, or even binary or varbinary).

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,935 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.