Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

VC++ problem with 64 bit oracle client with OpenforwardOnly flag in database connection.

Hi,
I am porting an existing windows based C++ application to 64 bit environment and this is one of those weird errors.
In the code snippet you can that I am using openforwardonly and it used to work fine with our old setup but in the 64 bit environment it gives the problem of fetching only ONE recordset. Or it could be a problem with the <b>MoveNext(); </b> of ADO.

To circumvent it we started using adOpenStatic and it worked fine for me for a while but only later realized that it has a performance hit and it is taking forever to get/iterative through values.
I request someone to try this code with both the flags and validate the behavior I am seeing.

Information about ado flags:
http://www.w3schools.com/ADO/met_rs_open.asp

Another EE topic
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_DB/Q_11520558.html

I remember seeing a MS support case but I can't get to it now.

I would appreciate any help or suggestions. I know we are using old technology but we want to move to the additional capabilities without changing code much.
// Dbtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <time.h>
 
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
 
int main(int argc, char* argv[])
{
 
HRESULT hr = S_OK;
    try
    {
      CoInitialize(NULL);
       
      _bstr_t strCnn("Provider=OraOLEDB.Oracle;Data Source =****; User Id=****; password=***");
	  _ConnectionPtr m_pConn;
		
	  hr=m_pConn.CreateInstance(__uuidof(Connection));
		
  
	  if(FAILED(hr))
	  {
			printf("Failed creating record set instance\n");
			return 0;
	  }
	  
	  m_pConn->Open(strCnn,"","",NULL);
 
      //Open the Record set for getting records from Author table
     _RecordsetPtr pRstDoctors = NULL;
	 time_t start,end1,end2;
	 pRstDoctors.CreateInstance(__uuidof(Recordset));
	 time(&start);
 
      pRstDoctors->Open("select logid from t_log",strCnn, adOpenForwardOnly,
		  adLockReadOnly,adCmdText);
 
      //Declare a variable of type _bstr_t
 
     int valField1;
     //int valField2;
 
     pRstDoctors->MoveFirst();
 
    //Loop through the Record set
    if (!pRstDoctors->EndOfFile)
    {
       while(!pRstDoctors->EndOfFile)
       {
		   valField1 = pRstDoctors->Fields->GetItem("phy")->Value.intVal;
         // valField2 = pRstDoctors->Fields->GetItem("reportid")->Value.intVal;
         // printf("%d - \n",valField1);
          pRstDoctors->MoveNext();
       }
    }
	time(&end1);
	
	double dif=difftime(end1,start);
    printf("time difference is %.2lf",dif);
   }
   catch(_com_error e)
   {
     printf("Error:%s\n",e);
   }
 
  CoUninitialize();
  return 0;
}

Open in new window

0
smalugu
Asked:
smalugu
  • 5
  • 4
  • 2
1 Solution
 
DanRollinsCommented:
Your SELECT command asks only for one field (logid), while it appears that your while loop expects other columns, such as reportID, phy, etc.
If you want to get a recordset of all of the columns, you should use adCmdTable
0
 
smaluguAuthor Commented:
Hi DanRollins,

Yes that's a typo. I have to change it now. I just didn't want to show queries used in the company :)
// Dbtest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <windows.h>
#include <stdio.h>
#include <time.h>
 
#import "C:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
 
int main(int argc, char* argv[])
{
 
HRESULT hr = S_OK;
    try
    {
      CoInitialize(NULL);
       
      _bstr_t strCnn("Provider=OraOLEDB.Oracle;Data Source =****; User Id=****; password=***");
          _ConnectionPtr m_pConn;
                
          hr=m_pConn.CreateInstance(__uuidof(Connection));
                
  
          if(FAILED(hr))
          {
                        printf("Failed creating record set instance\n");
                        return 0;
          }
          
          m_pConn->Open(strCnn,"","",NULL);
 
      //Open the Record set for getting records from Author table
     _RecordsetPtr pRstDoctors = NULL;
         time_t start,end1,end2;
         pRstDoctors.CreateInstance(__uuidof(Recordset));
         time(&start);
 
      pRstDoctors->Open("select logid from t_log",strCnn, adOpenForwardOnly,
                  adLockReadOnly,adCmdText);
 
      //Declare a variable of type _bstr_t
 
     int valField1;
     //int valField2;
 
     pRstDoctors->MoveFirst();
 
    //Loop through the Record set
    if (!pRstDoctors->EndOfFile)
    {
       while(!pRstDoctors->EndOfFile)
       {
                   valField1 = pRstDoctors->Fields->GetItem("logid")->Value.intVal;
         // valField2 = pRstDoctors->Fields->GetItem("reportid")->Value.intVal;
         // printf("%d - \n",valField1);
          pRstDoctors->MoveNext();
       }
    }
        time(&end1);
        
        double dif=difftime(end1,start);
    printf("time difference is %.2lf",dif);
   }
   catch(_com_error e)
   {
     printf("Error:%s\n",e);
   }
 
  CoUninitialize();
  return 0;
}

Open in new window

0
 
itsmeandnobodyelseCommented:
>>>> pRstDoctors->EndOfFile
I was used to EOF instead of  EndOfFile and the asp pages you referenced above tell from EOF only. Is the EndOfFile a synonym? And where is it defined?
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
smaluguAuthor Commented:
reply to itsmeanand...

I didn't define it anywhere, its how we are using it in our code base for finding out the end of a record. The compiler may be substituting something but I don't know for sure.
0
 
itsmeandnobodyelseCommented:
>>>> I didn't define it anywhere,
I wonder whether pRstDoctors->EOF  would compile as well (not that I really expect that it would be the solution for your issue).
0
 
smaluguAuthor Commented:
I actually wondered about it when I first saw this code. But yeah it sure does :)
0
 
DanRollinsCommented:
That is all set by the code line:
      no_namespace rename("EOF", "EndOfFile")
smalugu,
Did you try it this way?
   pRstDoctors->Open( "t_log", strCnn, adOpenForwardOnly, adLockReadOnly, adTable );
If you insist on using adCmdText, you can use the RecordCount member variable to see how many records matched the query.  
The first thing I do when a programmatic action does not work as I expected:  I use the database tools to try the same query.  I'm sure that Oracle provides an interactive environment that would allow you to evaluate your command text (the SELECT statement).
-- Dan
0
 
smaluguAuthor Commented:
DanRollins:

I haven't found any option like <b>adTable</b> you must be specifying adCmdTable which I tried after your suggestion but I am getting a com exception. Should I include some other files?

Thanks
0
 
DanRollinsCommented:
Yes, sorry about that.  The value i meant to use was:
   adCmdTable
It should work -- it is a standard way to use ADO to access a recordset (get all columns of a table and then cycle through the records).  What COM errors are you getting?
Here is a link to a question about ADO that includes a minimalist code sequence you can use:
    http://www.experts-exchange.com/Q_20161085.html#a6339004
 It is similar to what you already have, but it might help get you over these first hurdles.
0
 
DanRollinsCommented:
As this contains no specific, verified solution (though we tried!)  I recommend delete/no refund.
0
 
smaluguAuthor Commented:
Though did not solve the question had helped me a lot
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now