Oracle客户端与数据库连接中的OpenforwardOnly标志。

问题描述:

我正在将现有的基于Windows的C++应用程序移植到64位环境中,这是那些奇怪的错误之一。 在代码片段中,您可以使用我使用的openforwardonly,它用于使用我们的旧安装程序正常工作,但在64位环境中,它提供了只提取ONE记录集的问题。或者它可能是ADO的MoveNext();的问题。Oracle客户端与数据库连接中的OpenforwardOnly标志。

为了规避它,我们开始使用adOpenStatic,它对我有一段时间的工作很好,但后来才意识到它的性能受到影响,并且它正在永久获取/迭代值。 我请求有人用这两个标志尝试此代码并验证我所看到的行为。

有关ADO的标志上的信息: http://www.w3schools.com/ADO/met_rs_open.asp

另一个EE话题 http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_DB/Q_11520558.html

我记得看到一个MS支持的情况下,但我不能得到它现在。

我将不胜感激任何帮助或建议。我知道我们正在使用旧技术,但我们希望在不更改代码的情况下转向其他功能。

// 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 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; 
} 

使用 “ADOPENSTATIC” 而不是 “adOpenForwardOnly” 将工作

pRstDoctors->Open("select logid from log",strCnn, adOpenStatic, 
       **adLockReadOnly**,adCmdText);