OLEDB-C ++-ATL的OLEDB提供程序示例使Excel崩溃(msado15.dll中未捕获的异常)

时间:2018-07-06 21:08:44

标签: c++ com oledb ado atl

我已经编译了来自运行VS2007 ATL OLEDB Provider wizard的示例OleDb提供程序代码。我在该博客文章中提供了更详细的信息。代码使Excel崩溃。

Sub TestOleDbProvider()

    On Error GoTo ErrHand


    Dim cn As ADODB.Connection
    Set cn = New ADODB.Connection

    cn.Open "Provider=FindFiles;Server=foo;Database=bar" '* this works

    Dim cmd As ADODB.Command
    Set cmd = New ADODB.Command

    Set cmd.ActiveConnection = cn '* this works

    cmd.CommandText = "*.*"   '* this works

    Stop
    Dim rs As ADODB.Recordset
    Set rs = cmd.Execute '* crashes here

    Exit Sub
ErrHand:
    Debug.Print Err.Description & " (" & Err.Number & ")"
    'Stop

End Sub

上面的代码使Excel在Set rs = cmd.Execute行崩溃。如果我从VS2017调试,则会得到未处理的异常

enter image description here

未捕获异常的C ++调用堆栈在这里

msado15.dll!CQuery::SetSQL(unsigned short *) Unknown Non-user code. Symbols loaded.
msado15.dll!CQuery::SetCommandText(long,unsigned long,unsigned char,unsigned char) Unknown Non-user code. Symbols loaded.
msado15.dll!CQuery::Execute(enum ExecuteTypeEnum,char,unsigned long,bool,unsigned long,unsigned long,long,struct tagVARIANT *,unsigned long,void *,long *,struct _ADORecordset * *) Unknown Non-user code. Symbols loaded.
msado15.dll!CCommand::_Execute(enum ExecuteTypeEnum,char,unsigned long,bool,unsigned long,unsigned long,long,long,struct tagVARIANT *,unsigned long,void *,long *,struct _ADORecordset * *) Unknown Non-user code. Symbols loaded.
msado15.dll!CCommand::ExecuteWithModeFlag(struct tagVARIANT *,struct tagVARIANT *,long,struct _ADORecordset * *,int) Unknown Non-user code. Symbols loaded.
msado15.dll!CCommand::Execute(struct tagVARIANT *,struct tagVARIANT *,long,struct _ADORecordset * *) Unknown Non-user code. Symbols loaded.
VBE7.DLL!1e813579() Unknown No symbols loaded.
[Frames below may be incorrect and/or missing, no symbols loaded for VBE7.DLL]  Annotated Frame
VBE7.DLL!1e7cff4b() Unknown No symbols loaded.
VBE7.DLL!1e829d13() Unknown No symbols loaded.
VBE7.DLL!1e82fea2() Unknown No symbols loaded.
VBE7.DLL!1e82bcb5() Unknown No symbols loaded.
[External Code]  Annotated Frame

调用堆栈显示msado15.dll内部明显引发的异常

我应该想象这个用例没有得到定期测试,但是我会对任何建议感兴趣。

请问如何停止崩溃?

1 个答案:

答案 0 :(得分:1)

ADO(基于OLEDB的COM自动化包装器)查询OLEDB的ICommandText接口。而不是抱怨接口未实现,它只是继续使用NULL命令文本而崩溃。

我以为所有这些方法都可以正常工作,但是由于某种原因(OLEDB与ADO结合在一起使一项相当复杂的技术)不再可用,支持该命令的ATL模板实现了该接口,但在查询时不响应。

因此,要解决此问题,只需将ATL条目添加到命令对象的服务接口中即可:

BEGIN_COM_MAP(CFindFilesCommand)
    ...
    COM_INTERFACE_ENTRY(ICommandText) 
    ...
END_COM_MAP()