审核日志删除的最佳方法是什么?
连接字符串上的用户 ID 不是变量,并且与程序的用户 ID(例如可以是 GUID)不同。 如果连接字符串的用户 ID 是静态的,如何审核日志删除?
记录插入/更新/删除的最佳位置是通过触发器。 但是使用静态连接字符串,很难记录谁删除了某些内容。 还有什么选择呢?
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?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 SQL Server,您可以使用 CONTEXT_INFO 将信息传递给触发器。
我在代码中使用它(由网络应用程序调用),其中我必须使用触发器(例如表上的多个写入路径)。 这是无法将我的逻辑放入存储过程的地方。
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.
我们也有类似的情况。 我们的 Web 应用程序始终以同一数据库用户身份运行,但使用应用程序跟踪和控制的不同逻辑用户。
我们通常将逻辑用户ID作为参数传递到每个存储过程中。 为了跟踪删除,我们通常不删除该行,只是将状态标记为已删除,并相应地设置 LastChgID 和 LastChgDate 字段。 对于重要的表,我们保留审核日志(每个更改状态的副本),我们使用上述方法,并且触发器将行复制到审核表,LastChgID 已经正确设置,触发器不需要担心关于获取 ID。
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.