Discussion:
Invalid Descriptor Index
(too old to reply)
Sameer Motwani
2004-02-04 22:41:21 UTC
Permalink
Hi,
I am using MFC ODBC classes in my VC++ application for database accesss (on
a SQL Server/Access Database).
Some times after opening a Recordset I have to use the
CRecordset::GetFieldValue( LPCTSTR lpszName, CDBVariant& varValue, short
nFieldType = DEFAULT_FIELD_TYPE )
method of the CRecordset object to obtain field values. The above method
works fine with ODBC drivers for Jet but when I use ODBC for SQL Server it
throws the following exception

State:S1002,Native:0,Origin:[Microsoft][ODBC SQL Server Driver] Invalid
Descriptor Index

I don't understand why the Microsoft SQL Server ODBC Driver is throwing this
exception.

Please help me!

Sameer
Tian Min Huang
2004-02-05 08:06:09 UTC
Permalink
Hello Sameer,

Thanks for your post. As I understand, you fails to call
CRecordset::GetFieldValue with error "S1002 Invalid Descriptor Index".
Please correct me if there is any misunderstanding. I now share the
following information with you:

Based on my experience and research, the error is generally returned from
SQLGetData (the underlying ODBC API), and this error can be returned if you
call SQLGetData on a column that is already bound. If your Crecordset was
created with the AppWizard, it binds all the columns in the table and will
cause such error.

So the bottom line is that if you're using a CRecordset that was created
with the AppWizard, don't use GetFieldValue. Instead, go to the record that
you want and then look at the data member of the recordset (say,
m_FieldVariable) to get the field value.

I look forward to your result.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Sameer Motwani
2004-02-06 17:26:23 UTC
Permalink
Hi,
Thanks for the reply.

I understand that I have to go to record and look at the recordset data
memeber to get the field value, and this is what I have been using in most
of my code. But on some occassions I have to pass the CRecordset derived
object as a parameter to some functions which receives it as a const
reference (CRecordset& ) and uses the GetFieldValue function.
But I guess I will have to change that since it is not supported by the SQL
Server ODBC.

Sameer
Post by Tian Min Huang
Hello Sameer,
Thanks for your post. As I understand, you fails to call
CRecordset::GetFieldValue with error "S1002 Invalid Descriptor Index".
Please correct me if there is any misunderstanding. I now share the
Based on my experience and research, the error is generally returned from
SQLGetData (the underlying ODBC API), and this error can be returned if you
call SQLGetData on a column that is already bound. If your Crecordset was
created with the AppWizard, it binds all the columns in the table and will
cause such error.
So the bottom line is that if you're using a CRecordset that was created
with the AppWizard, don't use GetFieldValue. Instead, go to the record that
you want and then look at the data member of the recordset (say,
m_FieldVariable) to get the field value.
I look forward to your result.
Have a nice day!
Regards,
HuangTM
Microsoft Online Partner Support
MCSE/MCSD
Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Tian Min Huang
2004-02-09 03:36:54 UTC
Permalink
Hello Sameer,

Thanks for your response. After further research on this issue, I found
that we may be able to work around the problem by loading the cursor
library to support calls to SQLGetData() on bound columns. However,
forward-only and dynaset cursors do not enable the use of GetFieldValue()
in this manner to get the data of any bound column. So, we have to load up
the cursor library and open a snapshot recordset in order to get the
correct behavior when binding columns dynamically with MFC/ODBC classes .



The following is a code snippet that should do the trick:


//-------------------code snippet---------------------------

CDatabase *db = new CDatabase;

BOOL ReadOnly = FALSE;

LPCSTR lpszConnect = _T("ODBC;DSN=MySQL;UID=sa");

BOOL bUseCursorLib = TRUE; // To load the cursor library

db->Open( NULL, FALSE, ReadOnly, lpszConnect, bUseCursorLib );



CMyRecordset TestSet( db );

TestSet.Open(CRecordset::snapshot, "SELECT * FROM myTable");

//------------------------end of-------------------------


I am standing by for your result.


Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Sameer Motwani
2004-02-10 00:01:26 UTC
Permalink
Hi Tian,

It worked.

Thank You,
Sameer
Post by Tian Min Huang
Hello Sameer,
Thanks for your response. After further research on this issue, I found
that we may be able to work around the problem by loading the cursor
library to support calls to SQLGetData() on bound columns. However,
forward-only and dynaset cursors do not enable the use of GetFieldValue()
in this manner to get the data of any bound column. So, we have to load up
the cursor library and open a snapshot recordset in order to get the
correct behavior when binding columns dynamically with MFC/ODBC classes .
//-------------------code snippet---------------------------
CDatabase *db = new CDatabase;
BOOL ReadOnly = FALSE;
LPCSTR lpszConnect = _T("ODBC;DSN=MySQL;UID=sa");
BOOL bUseCursorLib = TRUE; // To load the cursor library
db->Open( NULL, FALSE, ReadOnly, lpszConnect, bUseCursorLib );
CMyRecordset TestSet( db );
TestSet.Open(CRecordset::snapshot, "SELECT * FROM myTable");
//------------------------end of-------------------------
I am standing by for your result.
Regards,
HuangTM
Microsoft Online Partner Support
MCSE/MCSD
Get Secure! -- www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
Loading...