gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 04:59:26 29 4
gpt4 key购买 nike

我已经编译了来自运行 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

上述代码在 Set rs = cmd.Execute 行使 Excel 崩溃。如果我从 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 内部引发的异常

我想这个用例没有定期测试,但我对任何建议都感兴趣。

请问如何停止崩溃?

最佳答案

ADO,OLEDB 上的 COM 自动化包装器,查询 OLEDB 的 ICommandText界面。它没有提示接口(interface)未实现,而是继续使用 NULL 命令文本并崩溃。

我原以为所有这一切都曾经有效,但由于某种原因不再有效(OLEDB 与 ADO 结合形成了一项相当复杂的技术),支持该命令的 ATL 模板实现了接口(interface)但在查询时不回答。

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

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

关于c++ - OLEDB - C++ - ATL 的 OLEDB 提供程序示例使 Excel 崩溃(来自 msado15.dll 的未捕获异常),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51217627/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com