开发者

Solutions for database access logging SQL Server 2008/ASP.NET 3.5

开发者 https://www.devze.com 2023-03-19 17:17 出处:网络
I have an ASP.NET 3.5 web app with SQL Server 2008 back end. There\'s a new requirement to log all the database access as follows:

I have an ASP.NET 3.5 web app with SQL Server 2008 back end.

There's a new requirement to log all the database access as follows:

For Selects:

  1. What stored procedure was executed
  2. What parameters were passed

For Inserts:

  1. What stored procedure was executed
  2. What parameters were passed
  3. Log inserted row(s)

For Updates:

  1. What stored procedure was executed
  2. What parameters were passed
  3. Log old row(s)
  4. Log new rows(s)

For Deletes:

  1. What stored procedure was executed
  2. What parameters were passe开发者_如何学编程d
  3. Log deleted row(s)

There's also a reporting requirement, but that's not that important at the moment.

Before I start writing my own logger, I was wondering if there's any solution out there that does this?

Change Data Capture looks promising, but only logs data changes (no Selects)

p.s.: My web app has a "local install" option where user buys the source code and hosts the app, so SQL Profiler will not work as a logger as described in this question


You can create a trace using tsql to capture all of the above. Since you mentioned that you cannot use the Profiler, simply use the system stored proc sp_trace_create to create the trace. user activity can be logged in a trace file. You can specify the max. size of the trace file and also intervals when you want to rotate the log files. Some of the other system SPs that you will need are:

  • SP_TRACE_CREATE
  • SP_TRACE_SETEVENT
  • SP_TRACE_SETFILTER
  • SP_TRACE_SETSTATUS

for reference: http://technet.microsoft.com/en-us/library/ms188662.aspx

for tutorial: http://sqlserverpedia.com/wiki/Running_Traces_with_TSQL

0

精彩评论

暂无评论...
验证码 换一张
取 消