将审计和归档信息生成到多个应用程序共享的 SQL 数据库中的最简单方法

发布于 2024-10-07 06:05:47 字数 386 浏览 0 评论 0原文

我们有几个应用程序正在更新某个 ms sql 2005 表(asp.net web 应用程序、c# windows 服务、电子邮件解析器到数据库自动化工具(使用 sql + VB)),并希望在表上存储审核信息。例如 ModifiedBy、ModifiedDate,其中 ModifiedBy = 更新记录的应用程序名称。

我们还想将表格上的信息存档;当我们更新特定记录时,将当前记录存储在 myTable_Archive 表中,并用日期标记它,并相应地更新 myTable 中的当前记录。

解决此问题同时将对现有应用程序的影响降至最低的最佳可维护和可测试方法是什么?或者有人可以建议更好的路线吗?例如,调用存储过程、c# 共享库(使用 nhibernate/ado.net 等)或 ms sql 2005 内置功能(如果有)。

We have several applications that are updating a certain ms sql 2005 table (asp.net web app, c# windows service, email parser to database automation tool (uses sql + VB)) and would like to store audit information on the table. E.g. ModifiedBy, ModifiedDate where ModifiedBy = Name of Application updating the record.

We would also like to archive the information on the table; when we update a particular record, store the current record in an myTable_Archive table and stamp it with a date and update the current record in myTable accordingly.

What's the best maintainable and testable approach to solving this while keeping the impact minimal to the existing applications? Or can someone suggest a better route? Calling a store procedure, c# shared library (using nhibernate/ado.net,etc.), or an ms sql 2005 built-in feature if any for example.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧伤慢歌 2024-10-14 06:05:47

进行此类审核的最可维护(且相当标准)的方法是使用 触发器 在有问题的表上。

由于它们完全存在于数据库中,因此您的应用程序根本不会改变。

当然,触发器会影响性能(因为现在在一次调用中更改多个表)。

The most maintainable (and fairly standard) way of doing this kind of auditing is to use triggers on the tables in question.

Since they exist entirely in the database, your applications will not change at all.

Of course, triggers will impact performance (since one now changes more than one table in a call).

深海不蓝 2024-10-14 06:05:47

我发现最简单的方法是通过触发器。要获取 ModifiedBy = 应用程序名称要求,您需要执行两件事

1) 更新连接字符串以设置应用程序名称
例如 ..Database=Foo;Application Name = Parser;

2) 然后在触发器中,您可以通过

select program_name from sys.dm_exec_sessions where session_id = @@SPID获取名称

I've found that the easiest is via triggers. To get the ModifiedBy = Name of Application requirement you'll need to do two things

1) Update the Connections strings to set the Application Name
e.g. ..Database=Foo;Application Name = Parser;

2) Then in your trigger you can get the name via

select program_name from sys.dm_exec_sessions where session_id = @@SPID

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文