简体   繁体   中英

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

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 passed
  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)

ps: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM