恢复 Sql Server 数据库后启用代理
我有启用了 Service Broker 的数据库。然后我想从其他数据库的备份中恢复程序中的数据库,但是恢复后(我在现有数据库名称上恢复),我的方法(启用 Service Broker)会出现此错误:
Msg 9772, Level 16, State 1, Line 1
The Service Broker in database "ServeDB2" cannot be enabled because there is already an enabled Service Broker with the same ID.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
这是我的方法:
public void TurnOnBroker()
{
if (!this.database.BrokerEnabled)
{
this.server.KillAllProcesses(this.database.Name);
this.database.BrokerEnabled = true;
this.database.Alter();
RefreshConnection();
}
}
我应该在这里修复什么?有什么建议吗?
I have DataBase with enabled Service Broker. Then I want to restore my database in program from backup of other database, but after restoring(I restore on existing database name), my method, whitch enables Service Broker, puts this error:
Msg 9772, Level 16, State 1, Line 1
The Service Broker in database "ServeDB2" cannot be enabled because there is already an enabled Service Broker with the same ID.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
This is my method:
public void TurnOnBroker()
{
if (!this.database.BrokerEnabled)
{
this.server.KillAllProcesses(this.database.Name);
this.database.BrokerEnabled = true;
this.database.Alter();
RefreshConnection();
}
}
What should i fix here?Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
记下这些选项,
如果您得到类似的信息,则已经是具有相同 ID 的已启用 Service Broker,请选择 NEW_BROKER
keep a note of these options
if youre getting something like this is already an enabled Service Broker with the same ID, go for the NEW_BROKER
这将创建新的服务代理
This will create the new service broker
每个数据库都有一个 Service Broker 使用的唯一 ID。此 ID 在 Sql Server 实例中的所有数据库中必须是唯一的(当然,它应该是全局唯一的,但 Sql Server 没有办法强制执行)。还原数据库时,您可以选择在还原的数据库中禁用 Service Broker,使用备份数据库的 GUID 启用它(以便它可以接管备份数据库的消息处理)或为其分配新的 GUID 。当您仍然拥有旧数据库并且遇到 GUID 冲突时,您尝试执行第二个选项。
有关详细信息,请参阅此处。
Every database has a unique ID used by Service Broker. This ID must be unique across all databases in a Sql Server instance (well, it should be unique globally, but Sql Server doesn't have a way to enforce that). When you restore a database, you have an option of disabling Service Broker in the restored database, enabling it with the GUID of the backed up database (so that it can take over message processing from the backed up database) or assign it a new GUID. You're trying to do the second option while you still have the old database around and you run into GUID conflict.
See here for more info.
运行此查询以找出哪些其他数据库正在使用与您正在使用的数据库相同的服务代理(例如,对于名为 DATABASE_NAME 的数据库)...
...返回...
然后运行以下查询以获得新的代理您的数据库...
再次运行第一个查询,您的数据库应该是列表中唯一的数据库......
现在返回...
Run this query to find out which other databases are using the same service broker as the database you are using (e.g. for a database called DATABASE_NAME)...
... returns ...
Then run the following queries to obtain a new broker for your database...
Run the first query again and your database should be the only one in the list...
... now returns ...
我找到了一个非常简单的解决方案 - 只需分配新的服务代理,如下所示:
I found a very simple solution for that- just simlpy assign new service broker, like this: