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:
- What stored procedure was executed
- What parameters were passed
For Inserts:
- What stored procedure was executed
- What parameters were passed
- Log inserted row(s)
For Updates:
- What stored procedure was executed
- What parameters were passed
- Log old row(s)
- Log new rows(s)
For Deletes:
- What stored procedure was executed
- What parameters were passe开发者_如何学编程d
- 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
精彩评论