简体   繁体   中英

Database operations tracking Application. Need to audit the changes made in the db

I have to create an application in .Net which will track the data changes in all the tables present in the DB without using Triggers .

I have some ideas which can be implemented to achieve the same.Need some suggestions from you guys.

  1. As all the operation will be present in fn_dblog table in Sql Server i have to read them based on the table name.
  2. While any DML command is fired i have to get the new and previous data based on a primary key and save it in another table which will be my AuditingTable.

Any more suggestion please enlighten me and suggest me which will be a good and efficient idea for this kind of application. I am using Sql Server as my db and my app will be in .Net framework.

I would suggest that you use the built in functionality: Change Data Capture

Change data capture records insert, update, and delete activity that is applied to a SQL Server table. This makes the details of the changes available in an easily consumed relational format. Column information and the metadata that is required to apply the changes to a target environment is captured for the modified rows and stored in change tables that mirror the column structure of the tracked source tables. Table-valued functions are provided to allow systematic access to the change data by consumers.

This has plenty of advantages:

  1. It reads from the transaction log, and it does not participate in the actual transaction

    The source of change data for change data capture is the SQL Server transaction log. As inserts, updates, and deletes are applied to tracked source tables, entries that describe those changes are added to the log.

  2. You can enable it per table. That means that since not all tables are there to be changed (ie lookup tables) you need not keep rows like this.
  3. You can setup how long you want to keep the history of these tables.

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