ExecuteXmlReader 和 null 结果集抛出 TargetInitationException

发布于 2024-07-14 13:27:18 字数 446 浏览 8 评论 0 原文

我正在 SQL Server 2005 数据库上调用一个存储过程,该过程返回 XML 结果集。 有时它会返回空结果集,因为没有要返回的行。 发生这种情况时,ExecuteXmlReader 方法将引发 TargetInitationException。 这似乎是一个已知问题(请参阅:http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/5e90e3c0-605b-406d-848a-dea7b16f458e/)。
处理此异常的最佳方法是什么?

I'm calling a stored procedure on a SQL Server 2005 database which returns an XML resultset. Sometimes it will return an null resultset becuase there are not rows to return. When this happens athe ExecuteXmlReader method throws a TargetInvocationException. This seems to be a known issue (see: http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/5e90e3c0-605b-406d-848a-dea7b16f458e/).
What is the best way to handle this exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

缺⑴份安定 2024-07-21 13:27:18

我可以想到 3 个选择

  1. 修改存储过程以返回虚拟/空值
  2. 修改代码 - 捕获异常并不执行任何操作 - 或记录错误
  3. 使用DataSet > - 您应该得到一个空的数据集,因此只需检查数据集是否为空。

作为第三个选择的相关 SO 帖子,这里有一个关于如何检查 DataSet 是否为空的问题

在 C# 中,测试数据集是否为空的最佳方法是什么?

I can think of 3 choices

  1. Modify stored procedure to return a dummy/empty value
  2. Modify code - catch exception and do nothing - or log error
  3. Use DataSet - You should get an empty DataSet so just check if DataSet is empty or not.

As a related SO post for the 3rd choice, here is a SO question on how to check if DataSet is empty or not

In C#, what is the best way to test if a dataset is empty?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文