• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

MSSQL ODBC getfieldvalue throwing exception

When I access my Access database using ODBC and getfieldvalue in forward field index order or backward index order I have no problems.
When I try to access the same database converted to MSSQL using a variety of converters and simply point at the new ODBC connection, DBCORE.CPP throws an error "GetFieldValue operation failed on field" if I try to fietch a field using an index less than the last field fetched.

My code (simplified) is :

    CString cstrg;

    rs.Open(CRecordset::dynaset,"SELECT * from DATAB");
    rs->GetFieldValue(5,cstrg);    \\Succeeds
    rs->GetFieldValue(7,cstrg);    \\Succeeds
    rs->GetFieldValue(4,cstrg);    \\ Fails

Is this a limitation of the MSSQL ODBC driver ?

To fetch in any other order is a real problems.

Any ideas ??


1 Solution
Jaime OlivaresCommented:
First step I suggest you is to compare field type of Access and MSSQL table.
PSernzAuthor Commented:

Field types are not a problem.  These are text fields that can be viewed and changed in MS SQL using any of the query tools without a problem.  I can access all the fields ok if I access them in index order.  If I try to access a field with an index earlier than the last index I get the error.

Very strange.

Does it still fail if you try by name instead of by ordinal value?
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Is the field null?  (That should not be a problem with string values but...)
PSernzAuthor Commented:
Have not tried name fetch.  Can't imagine it will make a difference.
The fields carry text.  All of the fields fail if you fetch a field with index less than the last field fetched.
PSernzAuthor Commented:
I've found the problem.
SQLGetData (used by getfieldvalue) can not fetch columns in reverse order. Documented....
Sounds incredible but true.
This means that ODBC routines used toward Access will not work for MS SQL.
Thanks Microsoft...
PAQed with points refunded (500)

Community Support Moderator

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now