保存更改失败,但没有抛出异常
我有一个例子,我正在调用 SaveChanges,它失败了,抛出了 try 块,但没有被捕获。我从未听说过这种情况,非常感谢您的帮助。
我在 Visual Studio 2008 中使用 C#,使用 .net Framework 3.5SP1。
有问题的代码是:
try
{
using (EntityConnection conn = new EntityConnection(_connName))
{
MWDPLCEntities contxt = new MWDPLCEntities(conn);
plcstatusmessage psmn = plcstatusmessage.CreatePLCStatusMessage(plcID, smID);
contxt.AddToplcstatusmessage(psmn);
contxt.SaveChanges();
}
}
catch(Exception ex)
{
LogService.addLog(ex.ToString(), LogService.LOG_EXCEPTION) ;
}
我在 SaveChanges 行之前和之后放置了日志语句,并且直接跟随的代码不会被打印。但是,异常也不会被记录,也不会保存数据。
老实说,我很困惑如何在不引发异常的情况下发生错误。我只能认为 C# 有其他一些方式报告我没有“捕获”的错误。
如果有人有指示或建议,我将不胜感激。
布鲁斯.
I have a case where I am calling SaveChanges, it is failing, throwing out of the try block, but not being caught. I have never heard of this happening, and your help would be appreciated.
I am using C# in Visual Studio 2008, with .net framework 3.5SP1.
The code in question is:
try
{
using (EntityConnection conn = new EntityConnection(_connName))
{
MWDPLCEntities contxt = new MWDPLCEntities(conn);
plcstatusmessage psmn = plcstatusmessage.CreatePLCStatusMessage(plcID, smID);
contxt.AddToplcstatusmessage(psmn);
contxt.SaveChanges();
}
}
catch(Exception ex)
{
LogService.addLog(ex.ToString(), LogService.LOG_EXCEPTION) ;
}
I have placed log statements before and after the SaveChanges line, and the one directly following does not get printed. However, the Exception does not get logged either, nor does the data get saved.
I am honestly puzzled as to how the error is happening without throwing an exception. I can only think that there is some other way that C# is reporting the error that I am not 'catching'.
If anyone has a pointer or suggestion, I would greatly appreciate it.
Bruce.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论