Solved

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

Posted on 2008-10-22
12
538 Views
Last Modified: 2013-12-12
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
Comment
Question by:smalugu
[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
  • 5
  • 4
  • 2
12 Comments
 
LVL 49

Expert Comment

by:DanRollins
ID: 22784533
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
 
LVL 1

Author Comment

by:smalugu
ID: 22786914
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22788152
>>>> 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 1

Author Comment

by:smalugu
ID: 22788188
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 22788757
>>>> 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
 
LVL 1

Author Comment

by:smalugu
ID: 22788775
I actually wondered about it when I first saw this code. But yeah it sure does :)
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 22791647
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
 
LVL 1

Author Comment

by:smalugu
ID: 22798472
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
 
LVL 49

Accepted Solution

by:
DanRollins earned 250 total points
ID: 22800164
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 24073140
As this contains no specific, verified solution (though we tried!)  I recommend delete/no refund.
0
 
LVL 1

Author Closing Comment

by:smalugu
ID: 31508960
Though did not solve the question had helped me a lot
0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that useā€¦
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

688 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