Solved

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

Posted on 2008-10-22
12
527 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
  • 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
 
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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

867 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

21 Experts available now in Live!

Get 1:1 Help Now