gpt4 book ai didi

c# - .net sql 异常处理 - 如何获取 sp 参数/值

转载 作者:太空宇宙 更新时间:2023-11-03 16:34:42 25 4
gpt4 key购买 nike

在 .net 开发中,当执行存储过程出错时,从异常中捕获存储过程的参数/值(或可能是整个语句)的最佳解决方案是什么?

有什么通用的解决方案吗?

环境---c#、.net、linq to sql、存储过程、wcf服务

谢谢

代码示例

public IEnumerable<string> GetCountries()
{
using (var db = new L2SDataContext(_connectionString))
{
var result = db.prime_ui_country_get();

return result.Select(item => item.country).ToList();
}
}

最佳答案

您可以从 SqlException.Errors Property 中获取错误信息(存储过程名称等) .至于参数/值,为什么不直接使用 SqlCommand 对象呢??

关于c# - .net sql 异常处理 - 如何获取 sp 参数/值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9503067/

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