将变更数据捕获用于小型桌面应用程序?

发布于 2024-07-11 15:22:45 字数 681 浏览 15 评论 0原文

我的一个新客户有一个 2002 年编写的小型 VB/Access 数据库应用程序,他希望重写该应用程序以使其更新并支持他长期以来一直想要的新功能。 因此,我将把它转换为在本地计算机上使用 C#.NET 2008 和 SQL Server Express 2008,并能够扩展到在远程服务器上使用 WCF 和 SQL Server 2008。

他感兴趣的新功能之一是维护和报告一段时间内数据更改的完整历史记录。 过去,我通过使用触发器和存储过程来完成此操作,这在@!#$中是一种痛苦。

我最近很想搞乱 SQL Server 2008 的更改数据捕获功能。在我最初使用它的一个小时内,我意识到它在 SQL 代理中创建了一个作业,默认情况下每 5 秒运行一次。 当我需要更改捕获的表的架构时,这似乎也有点痛苦。 除此之外,它似乎比我原来的方法更容易实现。 所以,这些是我的问题:

  1. 对于最终可能会或可能不会迁移到远程服务器的小型桌面应用程序来说,这是否太过分了?
  2. 在性能方面我应该期待什么? 随着他的数据库大小增加,我是否会接到更多他打来的电话,说他的计算机运行缓慢?
  3. 对于目前在生产中使用 CDC 的人来说,我还应该注意其他任何问题吗?
  4. 有没有人有任何链接,指向他们最喜欢的跟踪随时间变化的方式,这些方式可能更适合小型桌面应用程序?

谢谢,

马克

A new client of mine has a small VB/Access database application written in 2002 that he wants rewritten to bring it more up to date and to support new features he has been wanting for some time. So, I'm going to convert it over to use C#.NET 2008 and SQL Server Express 2008 on the local machine with the ability to scale to using WCF and SQL Server 2008 on a remote server.

One of the new features he is interested in is maintaining and reporting on complete history of data changes over a period of time. In the past, I've done this through the use of triggers and stored procedures, and it is a pain in the @!#$.

I have had an itch lately to mess with the Change Data Capture features of SQL Server 2008. During my initial hour of playing with it, I realized that it creates a job in SQL Agent that by default runs every 5 seconds. It also seems to be a bit more of a pain when I need to change the schema of captured tables. Other than that, it seems much easier to implement than my original method. So, these are my questions:

  1. Is this overkill for a small desktop application that might or might not eventually migrate over to a remote server?
  2. What should I expect in terms of performance? As his database size increases, am I going to get more calls from him saying that his computer is running slow?
  3. Are there any other gotchas with CDC that I should be aware of from anyone currently using it in production?
  4. Does anyone have any links to their favorite ways of tracking changes over time that might be a better fit for a small desktop application?

Thanks,

Marc

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

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

发布评论

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

评论(3

冷弦 2024-07-18 15:22:45

CDC 仅在 SQL Server Enterprise 版本中可用。 所以如果你有特快,你就不能使用它,你必须保持触发器。

CDC is only available in SQL Server Enterprise edition. so if you have express you can't use it and you'll have to remain with triggers.

羁客 2024-07-18 15:22:45

虽然触发器在很多方面都很难使用,但您可以通过编写实际生成触发器和历史表的脚本,在透明的数据审核历史记录机制上使用它们,而不会对主代码库产生任何影响自动地。 这是一项相当大的工作量,我不知道有谁做过这样的事情并将其开源,但这可能是一个有趣的项目。 至少这样,您可以编写一个生成器过程,然后就不必再弄乱各个触发器了。

While triggers are a pain to work with in many ways, you can use them layer on a transparent data audit history mechanism without any impact to the main codebase, by writing scripts that actually generate the triggers and history tables automatically. It's a fair amount of work, and I don't know of anyone who's done such a thing and open-sourced it, but it might be an interesting project. At least that way, you can write one generator procedure and then never have to mess with the individual triggers again.

就是爱搞怪 2024-07-18 15:22:45

我使用了自己的变更数据跟踪系统,在变更表中使用了 XML 列,使其更加灵活。 也使得触发器相当通用。

假设您已经有触发器来创建审核行,并且源表有一个名为“Version”、类型为 ROWVERSION 的列:

INSERT INTO [Changes].Sites
(
    SiteID,
    Operation,
    Version,
    ModifiedOn,
    DataChange
)
SELECT
    IsNull( I.SiteID, D.SiteID ),
    CASE
        WHEN D.[Version] IS NULL      AND I.[Version] IS NOT NULL  THEN 'I'
        WHEN D.[Version] IS NOT NULL  AND I.[Version] IS NOT NULL  THEN 'U'
        WHEN D.[Version] IS NOT NULL  AND I.[Version] IS NULL      THEN 'D'
        ELSE '?'
    END,
    IsNull( I.Version, D.Version ),
    SysDateTimeOffset(),
    (
        SELECT
            [Deleted] = ( SELECT * FROM deleted D1 WHERE D1.SiteID = D.SiteID FOR XML PATH(''), TYPE ),
            [Inserted] = ( SELECT * FROM inserted I1 WHERE I1.SiteID = I.SiteID FOR XML PATH(''), TYPE )
        FOR XML PATH('Changes')
    )
FROM deleted D
FULL JOIN inserted I
    ON D.SiteID = I.SiteID

该查询中唯一特定于我的表的内容是主键。 生成一个模板来创建这些查询将相当简单(甚至可以使用 sys.tables 等在 SQL 中完成)。

I've used my own change-data-tracking system using an XML column in my change-table, makes it more flexible. Also makes the trigger rather generic.

Assuming you already have triggers to create audit rows and your source table has a column named "Version" of type ROWVERSION:

INSERT INTO [Changes].Sites
(
    SiteID,
    Operation,
    Version,
    ModifiedOn,
    DataChange
)
SELECT
    IsNull( I.SiteID, D.SiteID ),
    CASE
        WHEN D.[Version] IS NULL      AND I.[Version] IS NOT NULL  THEN 'I'
        WHEN D.[Version] IS NOT NULL  AND I.[Version] IS NOT NULL  THEN 'U'
        WHEN D.[Version] IS NOT NULL  AND I.[Version] IS NULL      THEN 'D'
        ELSE '?'
    END,
    IsNull( I.Version, D.Version ),
    SysDateTimeOffset(),
    (
        SELECT
            [Deleted] = ( SELECT * FROM deleted D1 WHERE D1.SiteID = D.SiteID FOR XML PATH(''), TYPE ),
            [Inserted] = ( SELECT * FROM inserted I1 WHERE I1.SiteID = I.SiteID FOR XML PATH(''), TYPE )
        FOR XML PATH('Changes')
    )
FROM deleted D
FULL JOIN inserted I
    ON D.SiteID = I.SiteID

The only thing in that query that's specific to my table is the primary key. Generating a template to create those queries would be rather simple (could even do it in SQL using sys.tables etc).

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