数据库架构更改时对 SqlCacheDependency 和 Broker Service 的影响

发布于 2024-12-14 23:54:05 字数 304 浏览 6 评论 0原文

我正在创建一个具有 Sql 缓存依赖项的应用程序。

启用了代理

Alter database test ENABLE_BROKER

为此,我在向数据库添加两个新表后

。但我发现我无法为我添加的新表获得任何通知服务。

即使我使用

Alter datatbase test New_Broker

这个命令仍在运行,所以我取消它但没有成功。

您能具体说明我缺少什么吗?

有任何帮助吗?

I am creating an application with Sql cached dependency.

For this i enabled the broker by

Alter database test ENABLE_BROKER

After i add two new tables to the database.

But i found that i am not able to get any notification services for the new tables that i added.

Even i use

Alter datatbase test New_Broker

THis command keeps on running so i cancel it without any success.

Can you please specify what i am missing

Any help is apprciated

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

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

发布评论

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

评论(1

分分钟 2024-12-21 23:54:05

您似乎在问两个问题:

  1. 如何防止 SET ENABLE_BROKER 挂起

    ALTER DATABASE [YourDBName] SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE

  2. 架构更改时,您能收到 Service Broker 通知吗?< /p>

通知仅适用于现有表。这可能会导致您考虑尝试注册对 sys.tables 的依赖项,但在通知查询中不允许使用系统视图和表。

您应该能够通过设置插入特殊表的 DDL 触发器,然后针对该表发出查询来解决此问题。例如:

CREATE TRIGGER [MyTrigger] ON DATABASE AFTER CREATE_TABLE AS ...

It seems like you're asking two questions:

  1. How to prevent SET ENABLE_BROKER from hanging

    ALTER DATABASE [YourDBName] SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE

  2. Can you get notified by Service Broker when the schema changes?

Notifications are for existing tables only. This might lead you to consider trying to register a dependency against sys.tables, but system views and tables are not allowed in a query for notifications.

You should be able to work around this by setting up a DDL trigger that inserts into a special table, and then issue queries against that table. For example:

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