Solved

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

Posted on 2008-10-22
12
536 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle Errors 11 79
Security and Directory services expertise required for the Analysis of service account weird behavior 2 150
Adjust the codes 3 60
Example code 13 36
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.

740 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