Oracle客户端在数据库连接中使用OpenforwardOnly标志。

时间:2022-09-01 11:14:57

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 MoveNext(); of ADO.

我正在将现有的基于Windows的C ++应用程序移植到64位环境中,这是其中一个奇怪的错误。在代码片段中,您可以使用openforwardon,它曾经与我们的旧设置工作正常,但在64位环境中,它提出了只获取一个记录集的问题。或者它可能是MoveNext()的一个问题; 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.

为了规避它,我们开始使用adOpenStatic,它对我有一段时间没有用,但后来才意识到它有性能损失,并且需要永远地通过值获得/迭代。我请求有人用这两个标志尝试这个代码并验证我看到的行为。

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

有关ado标志的信息: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

另一个EE主题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.

我记得看过一个MS支持案例,但我现在无法理解。

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

1 个解决方案

#1


1  

Using "adOpenStatic" instead of "adOpenForwardOnly" will work

使用“adOpenStatic”而不是“adOpenForwardOnly”将起作用

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

#1


1  

Using "adOpenStatic" instead of "adOpenForwardOnly" will work

使用“adOpenStatic”而不是“adOpenForwardOnly”将起作用

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