1

I am wondering what would be the best practice to logging when a user inserts or updates some data from my ASP.NET application.

In my application I need to know which user made the change, I think I have to options:

  • Register my ASP.NET users into the SQL Server adding them the rights for the tables needed, and store for each of my users individual connectionstring. Thus I could use the currently logged in user's connectionstring when connecting to the database, so that I could write T-SQL triggers for SELECT and UPDATE.

  • The other option I thought of is that I can write stored procedures that get the ASP.NET user name as input parameter and makes the log for me, (I use only one connectionstring in the application). After modifying the database from the application I would call this procedure giving the currently logged in user's username.

The second option seems simpler to me, but I think that for that purpose I should choose the first option.

1
  • The second option is simple. Further more create a users in data base with rights. Means weather he can make changes or not. Rather than working on name you can use the id field of the database. You can also use trigger to keep log of user changes made to your database. Here is a nice article on trigger codeproject.com/Articles/25600/Triggers-Sql-Server Jan 4, 2013 at 11:03

1 Answer 1

1

Go for the second option. Managing users in a database creates more of a headache for you and what happens if you have to move the database server? You would need to update all of the connection strings for all the users. It just creates an extra admin overhead.

Furthermore, if you need to log all the changes in the database then I have come up with something that I have used in the past to store all changes made to a database over time. Have a look, it might be useful.

http://richhooper.wordpress.com/2012/06/11/sql-server-row-level-versioning/

3
  • Thanks for the reply. Yes, I think you are right about having much more trouble with the first option, and in the future I may will think about the row versioning as well.
    – dvjanm
    Jan 4, 2013 at 14:08
  • But just to mention a disadvantage of the second choice, it duplicates the database connects, because after every insert or update I have to call the stored procedure that makes the logging.
    – dvjanm
    Jan 4, 2013 at 15:05
  • Well you could make sure that you open and hold a connection to the database and use it for both sql statements (insert/update and stored procedure). Besides the .net framework will try to reduce this with connection pooling. msdn.microsoft.com/en-us/library/8xx3tyca.aspx Jan 7, 2013 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.