Home Dashboard Directory Help

MFC - CRecordset::GetFieldValue throws "Invalid Argument Value" exception when reading a Non-null SQL Server VARBINARY(MAX) Field value by Goldorak84


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 692769
Opened: 10/3/2011 8:27:08 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
User(s) can reproduce this bug


In MFC, while trying to read data from a SQL Server VARBINARY(MAX) field, the CRecordset::GetFieldValue function asserts in dbcore.cpp, at
void* PASCAL CRecordset::GetDataBuffer(CDBVariant& varValue,
    short nFieldType, SQLLEN* pnLen, short nSQLType, SQLULEN nPrecision)
function, in the line
    // better know the length!
             ASSERT(nPrecision != 0);
    *pnLen = nPrecision;

After that, it throws an "Invalid Argument Value" exception. I can't read the value.
It worked before with SQL Server's IMAGE type, but it's deprecated, so I try not to use it
Sign in to post a comment.
Posted by Goldorak84 on 10/27/2011 at 11:26 AM
Is it possible to get a hotfix for this?
Posted by Microsoft on 10/25/2011 at 4:46 PM

Thanks again for the report. This issue has been fixed in MFC for the next major release of Visual Studio.

Pat Brenner
Visual C++ Libraries Development
Posted by Goldorak84 on 10/11/2011 at 10:43 AM
Hi Pat, No, my application doesn't work in release. The code doesn't seem to handle the nPrecision==zero case, it results in an exception thrown.
Posted by Microsoft on 10/7/2011 at 1:02 PM

Thanks for the report. It's possible that the assertion is invalid (in other words, it may be valid for nPrecision to be zero). Does your application work in Release configuration? Can you step through the code and verify that the nPrecision=zero case is handled correctly?

I may be able to fix the issue by simply removing the assertion, so I want to check whether that is a valid fix. Thanks!

Pat Brenner
Visual C++ Libraries Development
Posted by MS-Moderator07 [Feedback Moderator] on 10/3/2011 at 7:34 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by MS-Moderator01 on 10/3/2011 at 8:40 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Goldorak84 on 10/11/2011 at 10:48 AM
I found a workaround for this bug, but it's requires having to subclass CRecordset.
Simply implement the "virtual void PreBindFields()" CRecordset function and put that code

void YourDerivedClass::PreBindFields()
    for(int i = 0; i < GetODBCFieldCount(); i++)
        CODBCFieldInfo* pFieldInfo = m_rgODBCFieldInfos + i;
        if(pFieldInfo->m_nSQLType == SQL_VARBINARY && !pFieldInfo->m_nPrecision)
            pFieldInfo->m_nSQLType = SQL_LONGVARBINARY;
            pFieldInfo->m_nPrecision = INT_MAX;

Although this works, I would prefer a bug fix from Mr Brenner and the Microsoft MFC team.