1

I want to know , If I can catch all errors occurred in my database and log it to some user defined table.

Reason:

Why I am as so is that, I have web-app running with Sql2005 as backend. Web app is developed using Linq2Sql. It was developed on 2008R2 where as deployed over Sql2005 on a Shared Hosting environment.

I am continuously getting datetime datatype error, as in 2008 i have used date datatype.

So, what I want is to catch any similar exceptions internally , occurred anywhere in my database and log it to my custom table with fields

Requirements

  1. Table Name from where the exception has been thrown
  2. Name of Procedure, in case if I use it in future
  3. Exception message
  4. Date time of occurrence

Please Note

I dont want to write tablewise exception handling procedures. I want some generic way to get all exceptions, as same as we handle errors in ASP.Net , Global.asax.

Exception I am getting

The version of SQL Server in use does not support datatype 'date'.

based on above exception, I am not sure which table is throwing this exception. So I want a stored procedure to catch the detail and save to my custom table.

4

1 回答 1

1

Those errors aren't internal to SQL server. It's probably not even SQL that's giving it to you but rather the db drivers.

If you are using stored procedures, then SQL server would have prevented those s'procs from even being created with the unsupported data type usage.

Considering you are using LINQ, my guess is that LINQ itself is throwing the problem and you'll need to use your regular exception handling around database calls to find it.

Of course, a better path, would be to regenerate your model and/or do a code analysis to locate all references to invalid data types. Or, even better, switch to a host that is somewhat up to date with their version of SQL server. There have been a lot of security and performance improvements since then.

于 2013-03-07T14:31:54.897 回答