gpt4 book ai didi

.net - 如何捕获特定的 OleDbException?

转载 作者:行者123 更新时间:2023-12-01 16:19:05 25 4
gpt4 key购买 nike

我需要捕获以下特定异常:

System.Data.OleDb.OleDbException was caught ErrorCode=-2147467259
Message="The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again." Source="Microsoft JET Database Engine" StackTrace: at System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(OleDbHResult hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery()

我不确定 ErrorCode 是什么,但它看起来不可靠。

我可以相信 Message 在不同平台上是相同的吗?

我能否以某种方式使用在堆栈跟踪中找到的 OleDbHResult hr 值? (参见 https://stackoverflow.com/a/991660/327528)

Message 进行文本搜索以查找 duplicateprimary key 之类的词的唯一解决方案是什么?

最佳答案

您是对的,ErrorCode (-2147467259 = 0x80004005 = E_FAIL) 太笼统了,依赖消息非常脆弱 - 例如考虑本地化。

我会查看 OleDbException.Errors 集合以尝试找到更具体的内容。

关于.net - 如何捕获特定的 OleDbException?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12796934/

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