诗岑 2023-12-20 08:46 采纳率: 93%
浏览 33
已结题

【C++】程序“[9444] ado.exe: 本机”已退出,返回值为 -1073741510 (0xc000013a

源代码:

#import "C:\Program Files\Common Files\System\ado\msado15.dll" \
    no_namespace rename("EOF","EndOfFile")

#include<Ole2.h>
#include<stdio.h>
#include<conio.h>

inline void TESTHR(HRESULT x) {  
    if (FAILED(x)) {  
        _com_issue_error(x);  
    }  
}
void CountX(void);
void PrintProviderError(_ConnectionPtr pConnection);
void PrintComError(_com_error &e);

void main(){
    if(FAILED(::CoInitialize(NULL)))
        return;
    CountX();
    ::CoUninitialize();
}

void CountX(){
    //define ADO object pointers
    _RecordsetPtr pRstEmployee=NULL;
    //define other variables
    HRESULT hr=S_OK;
    _variant_t Index;
    Index.vt=VT_I2;
    int j=0;
    _bstr_t strCnn("Provider=SQLOLEDB;Data Source=srv;"
        "Initial Catalog=Pubs;User Id=system;Password=123456;");
    try{
        //open recordset with data from employee table
        TESTHR(pRstEmployee.CreateInstance(_uuidof(Recordset)));
        pRstEmployee->Open("Employee",strCnn,adOpenForwardOnly,
            adLockReadOnly,adCmdTable);
        //print information about fields collection
        printf("\n%d Fields in Employee\n",pRstEmployee->Fields->Count);
        for(int intLoop=0;intLoop<=(pRstEmployee->Fields->Count-1);intLoop++){
            Index.iVal=intLoop;
            printf(" %s\n",(LPSTR) pRstEmployee->Fields->GetItem(Index)->Name);

        }
        //print information about properties collection
        printf("\n%d Properties in Employee\n",pRstEmployee->Properties->Count);
        for(int intLoop=0;intLoop<=(pRstEmployee->Properties->Count-1);intLoop++){
            j++;
            Index.iVal=intLoop;
            printf(" %s\n",(LPSTR) pRstEmployee->Properties->GetItem(Index)->Name);
            if(((j%23)==0)||(intLoop==11)){
                printf("\nPress any key to continue...");
                getch();
                //clear the screen for the next display
                system("cls");
                j=0;
            }
        }
        //clean up object before exit
        pRstEmployee->Close();
    }
    catch(_com_error &e){
        //nodify user of any errors that result from executing the query
        _variant_t vtConnect=pRstEmployee->GetActiveConnection();
        switch(vtConnect.vt){
            case VT_BSTR:
                PrintComError(e);
                break;
            case VT_DISPATCH:
                PrintProviderError(vtConnect);
                break;
            default:
                printf("Errors occured");
                break;
        }
    }
}

void PrintProviderError(_ConnectionPtr pConnection){
    ErrorPtr pErr=NULL;
    if((pConnection->Errors->Count)>0){
        long nCount=pConnection->Errors->Count;
        for(long i=0;i<nCount;i++){
            pErr=pConnection->Errors->GetItem(i);
            printf("Error number:%x\t%s\n",pErr->Number,pErr->Description);
        }
    }
}

void PrintComError(_com_error &e){
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    printf("Error\n");
    printf("\tCode=%081x\n",e.Error());
    printf("tCode meaning=%s\n",e.ErrorMessage());
    printf("\tSource=%s\n",(LPCSTR) bstrSource);
    printf("\tDescription=%s\n",(LPCSTR) bstrDescription);
}

调试结果:

“ado.exe”: 已加载“C:\Users\Administrator\Desktop\ado\Debug\ado.exe”,已加载符号。
“ado.exe”: 已加载“C:\Windows\SysWOW64\ntdll.dll”,已加载符号(去除源信息)。
“ado.exe”: 已加载“C:\Windows\SysWOW64\kernel32.dll”,已加载符号(去除源信息)。
“ado.exe”: 已加载“C:\Windows\SysWOW64\KernelBase.dll”,已加载符号(去除源信息)。
“ado.exe”: 已加载“C:\Windows\SysWOW64\ole32.dll”,已加载符号。
“ado.exe”: 已加载“C:\Windows\SysWOW64\ucrtbase.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\rpcrt4.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\combase.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\gdi32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\win32u.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\gdi32full.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msvcp_win.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\user32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\oleaut32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msvcr100d.dll”,已加载符号。
“ado.exe”: 已加载“C:\Windows\SysWOW64\imm32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\kernel.appcore.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msvcrt.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\bcryptprimitives.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\uxtheme.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\clbcatq.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\ado\msado15.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\advapi32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\sechost.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msdart.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\oledb32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\bcrypt.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\dpapi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\WinSxS\x86_microsoft.windows.common-controls_6595b64144ccf1df_6.0.19041.3636_none_a863d714867441db\comctl32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\comsvcs.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\sqloledb.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\crypt32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\netapi32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\Common Files\System\Ole DB\msdatl3.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\cryptbase.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\version.dll”,Cannot find or open the PDB file
“ado.exe”: 已卸载“C:\Windows\SysWOW64\version.dll”
“ado.exe”: 已加载“C:\Windows\SysWOW64\dbnetlib.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\ws2_32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\security.dll”,Cannot find or open the PDB file
“ado.exe”: 已卸载“C:\Windows\SysWOW64\security.dll”
“ado.exe”: 已加载“C:\Windows\SysWOW64\security.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\secur32.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\sspicli.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\msv1_0.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\NtlmShared.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\cryptdll.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\ntdsapi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\dsparse.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\mswsock.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\dnsapi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\IPHLPAPI.DLL”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\nsi.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Program Files (x86)\National Instruments\Shared\mDNS Responder\nimdnsNSP.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\nimdnsResponder.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\WinSxS\x86_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.9625_none_508ef7e4bcbbe589\msvcr90.dll”,Cannot find or open the PDB file
“ado.exe”: 已加载“C:\Windows\SysWOW64\rasadhlp.dll”,Cannot find or open the PDB file
线程 'Win32 线程' (0x1f08) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x3174) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x10a0) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x1ac8) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x318c) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x3220) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0xe00) 已退出,返回值为 -1073741510 (0xc000013a)。
线程 'Win32 线程' (0x3170) 已退出,返回值为 -1073741510 (0xc000013a)。
程序“[9444] ado.exe: 本机”已退出,返回值为 -1073741510 (0xc000013a)。

  • 写回答

1条回答 默认 最新

  • 编程乐学 2023-12-20 10:42
    关注

    检查文件路径:确保 msado15.dll 文件位于 C:\Program Files\Common Files\System\ado\ 目录下。如果文件不存在或位置不正确,您可以尝试使用正确的文件路径。

    检查数据库连接字符串:请确保数据库连接字符串中的服务器名、数据库名、用户名和密码正确无误。如果您不确定这些信息,请与数据库管理员联系以获取正确的连接字符串。

    检查数据库和表的存在性:确保数据库和表存在并且可访问。您可以使用其他数据库管理工具(如SQL Server Management Studio)来验证数据库和表的存在性,并确保您具有足够的权限访问它们。

    检查代码逻辑:在您的代码中,有一些地方可能会导致问题。首先,您在打开记录集时使用了 adCmdTable 参数,这意味着您试图打开一个名为 "Employee" 的表。请确保该表存在,并且没有拼写错误。其次,您在异常处理块中访问了 pRstEmployee 对象的属性,但是在异常发生时,pRstEmployee 对象可能为空。您可以在访问 pRstEmployee 对象之前添加一个非空判断。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 12月28日
  • 已采纳回答 12月20日
  • 创建了问题 12月20日