Fraz Sundal
Fraz Sundal

Reputation: 10448

I want to track every insert/update/delete sql operation in my ASP.Net MVC CMS

I want to implement event management in my application and i wanna know what may be the best practice to achieve this goal. Event management in my case is to maintain a log of every insert/update/delete operation in my application.

Upvotes: 1

Views: 516

Answers (4)

Mathias F
Mathias F

Reputation: 15891

Use Change Data Capture http://www.mssqltips.com/tip.asp?tip=1474

Upvotes: 1

John Bledsoe
John Bledsoe

Reputation: 17642

What data access layer are you using? If you're using LINQ to SQL or Entity Framework you could hook into events in their contexts to track these operations. Or, if you have a service tier through which these operations all flow, you could raise events there.

Specifically, since you are using LINQ to SQL, then you can implement the partial methods InsertEntity, UpdateEntity, and DeleteEntity (where Entity is the name of each of your entities) on your strongly-typed DataContext. These hooks should be the exact place to perform your logging or other event processing.

Upvotes: 1

Johannes Setiabudi
Johannes Setiabudi

Reputation: 2077

I agree with the answer that it can be done in the DB layer by using triggers. If you don't want to put it in the db layer, you can create an action filter for all of your actions (add/update/delete) - which writes to the log.

Upvotes: 0

Robert
Robert

Reputation: 3398

It sounds like you are refering to a database event, in that case i would use triggers on the db and not bother with any ASP.Net implementation.

Upvotes: 3

Related Questions