views:

247

answers:

2

The user id on your connection string is not a variable and is different from the user id (can be GUID for example) of your program. How do you audit log deletes if your connection string's user id is static?

[EDIT]

The best place to log insert/update/delete is through triggers. But with static connection string, it's hard to log who delete something. What's the alternative?

+1  A: 

With SQL Server, you could use CONTEXT_INFO to pass info to the trigger.

I use this in code (called by web apps) where I have to use triggers (eg multiple write paths on the table). This is where can't put my logic into the stored procedures.

gbn
A: 

We have a similar situation. Our web application always runs as the same database user, but with different logical users that out application tracks and controls.

We generally pass in the logical user ID as a parameter into each stored procedure. To track the deletes, we generally don't delete the row, just mark the status as deleted, set the LastChgID and LastChgDate fields accordingly. For important tables, where we keep an audit log (a copy of every change state), we use the above method and a trigger copies the row to a audit table, the LastChgID is already set properly and the trigger doesn't need to worry about getting the ID.

KM