ASP.NET 动态数据中的异常
我有一个 ASP.NET 动态数据应用程序(使用实体框架),在尝试数据库插入时我刚刚发现重复键错误。但是,我必须使用 SQL Profiler 来查找错误。插入模板页面只是默默地什么也没做。
我如何捕获这样的错误并记录它们并可能显示一条消息?
I have an ASP.NET Dynamic Data application (using Entity Framework) in which I have just discovered a duplicate key error when attempting a database insert. However, I had to use SQL Profiler to find the error. The insert template page just silently did nothing.
How can I trap errors like this and log them and maybe display a message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果未捕获,则可以在 DetailsView 和 DataSource 控件上的 CUD 事件参数中检测到异常,例如
DetailsView_ItemInserted
和DetailsDataSource_Inserting
等事件具有Exception 异常
和bool ExceptionHandled
属性用于处理异常。Exceptions can be detected, if not caught, in the CUD event arguments on the DetailsView and the DataSource controls, e.g. events such as
DetailsView_ItemInserted
, andDetailsDataSource_Inserting
haveException Exception
andbool ExceptionHandled
properties for handling exceptions.您可以在动态数据站点中实现的另一种方法是使用自定义派生的 DynamicValidator 控件。
有关详细信息,请参阅链接 处理动态数据中的数据库异常
Another approach that you could implement in Dynamic Data site is using a custom derived DynamicValidator control.
For detail information, please, refer to the link Handling database exceptions in Dynamic Data