Solved

CRecordset "Invalid Descriptor Index "

Posted on 2014-04-15
6
431 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
  • 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Help with SQL Query 23 39
C++ mouse_event mouse look 7 27
Azure SQL DB? 3 21
Caste datetime 2 24
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now