如何在表中插入错误消息 [英] How to insert the error message in table
问题描述
大家好,
我正在研究一个项目,在我的项目中我陷入了一个场景,我需要维护一个错误日志。我创建了一个错误日志表,其中我有列名称错误消息。我想在该列中插入错误消息。因为我正在使用标识列,现在如果有人为该标识列插入值而不使用设置标识,则会显示错误消息,如无法插入显式值当IDENTITY_INSERT设置为OFF时,表'example'中的标识列。我希望该错误信息在我的表格中作为记录。
我应该如何实现这一目标。
你的帮助会很明显。
谢谢
Hi all,
I am working on a project, in my project I am stuck in a scenario, where i need to maintain a error log. I created a error log table in which i have column name Error Message. I want to insert the error message in that column.for ex I am using a identity column, now if someone insert a value for that identity column without using "Set Identity On" then a error message is displayed like "Cannot insert explicit value for identity column in table 'example' when IDENTITY_INSERT is set to OFF." i want that error message to be as record in my table.
How should I achieve that.
Your help will be appreciable.
Thanks
推荐答案
尝试把try,catch block .. :)
try to put try , catch block.. :)
BEGIN TRY
...do your stuff
END TRY
BEGIN CATCH
get the ERROR_LINE(), ERROR_MESSAGE()
--Save error into table from here
END CATCH
查看此文章。
使用数据库的错误记录技术 [ ^ ]
这篇关于如何在表中插入错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!