Solved

CRecordset "Invalid Descriptor Index "

Posted on 2014-04-15
6
481 Views
Last Modified: 2014-04-22
Hi all,

Here's my code:

SQL = SELECT ID,X,Y,A,TYPEID, vid  FROM (SELECT ID,A,X,Y,TYPEID,  (SELECT TOP 1 ID FROM DETAILS d WHERE pos.ID = d.ID) AS vid, row_number() over (partition by ID order by CREATEDTIME desc) as rn FROM POST pos) AS ss WHERE rn = 1;

CDatabase* pDatabase = new CDatabase();
pDatabase->Open(_T(""),FALSE,FALSE,LPCTSTR(sDsn));
CRecordset rs( pDatabase );
rs.m_bUseODBCCursorLib = TRUE;
BOOL iReturn = rs.Open(SQL ,CRecordset::forwardOnly,CRecordset::readOnly);
while(!rs.IsEOF() )
{
    CDBVariant v;
    memset(&v,0,sizeof(CDBVariant));
            
  rs.GetFieldValue((short)0, v, SQL_C_SLONG);
   //always the ERROR here
}

I searched high and low, but so far unable to solve this.

Maybe there's something wrong with my SQL? But
this only happens on SQLServer (I tried different databases on different versions).
Works fine in DB2.

Please help.
0
Comment
Question by:trustworthy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 40002070
Is that really your actual code? I am asking because

BOOL iReturn = rs.Open(SQL ,CRecordset::forwardOnly,CRecordset::readOnly);

Open in new window


really seems wrong, all versions of 'CRecordset::Open()' take 'nOpenType' as their 1st parameter and the SQL statement as the 2nd, see the docs at http://msdn.microsoft.com/en-us/library/1hkkwdf0%28v=vs.120%29.aspx

Also, what is the return value? Are you checking that one before calling 'GetFieldValue()'?
0
 

Author Comment

by:trustworthy
ID: 40002149
You're right, I copied the wrong statement, it is:

rs.Open(CRecordset::forwardOnly,sp_text,CRecordset::readOnly);

And yes, I do check the return value, and I see number of records returned in the rs properties.
0
 
LVL 86

Expert Comment

by:jkr
ID: 40003107
OK, and when you open the Data Set Visualizer in VS (just hover over the record set in the debugger and click on the magnifier symbol), do you get the results that you expected n terms of that query?
0
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 

Author Comment

by:trustworthy
ID: 40003726
Yes, exactly what is expected. Same number of rows if I run the same query in any SQL program.
0
 

Accepted Solution

by:
trustworthy earned 0 total points
ID: 40007642
I can't figure this out, so I decided not to use CRecordset at all
0
 

Author Closing Comment

by:trustworthy
ID: 40014367
Bo other solution
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question