shpresa
asked on
How to catch errors while executing on C# and storing the errors in a database
Hi I created this table called tbl_Error and i want automatically anytime I execute store procedures in my web applications to store the following data errors
time storeProc error
-------------------------- ---------- ---------- ---------- ---------- ---------- -----
4/5/2011 sp_SurveyUpdate Error converting data type nvarchar to int.
Any suggestion where I can instert this fields. I know it is duable.
time storeProc error
--------------------------
4/5/2011 sp_SurveyUpdate Error converting data type nvarchar to int.
Any suggestion where I can instert this fields. I know it is duable.
we can achive this error logging 2 ways
1) UI Level
write try catch blocks for every method which is having DB intaraction.
In Catch black you need to call a DB to insert the error and time, any other details
2) DB Level
Write below code
For ex:
Insert
Into
.
.
.
.
If @@Error > 0
Begin
Insert
Into tbl_Error
.
.
.
.
Select 0 As Success
End
else
Begin
Select 1 As Success
End
1) UI Level
write try catch blocks for every method which is having DB intaraction.
In Catch black you need to call a DB to insert the error and time, any other details
2) DB Level
Write below code
For ex:
Insert
Into
.
.
.
.
If @@Error > 0
Begin
Insert
Into tbl_Error
.
.
.
.
Select 0 As Success
End
else
Begin
Select 1 As Success
End
Hello,
You have to put every possiblities of error are store into the Exception and then after you have to store this exception values into the database. You also create a log file of errors.
You have to put every possiblities of error are store into the Exception and then after you have to store this exception values into the database. You also create a log file of errors.
ASKER
Thank you for the solutions experts.
To jagssidurala:
I find it easier to follow the DB Level. Do I write that store procedure and call it somewhere in the coding..if so where ?
Thanks in advance
To jagssidurala:
I find it easier to follow the DB Level. Do I write that store procedure and call it somewhere in the coding..if so where ?
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Easy and strait forward solution.
-MJC