4

尝试从我的数据库发送消息时出现权限错误。

我启用了 proker 服务:

-- Enable Broker on Initiator
ALTER DATABASE A-DB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
ALTER DATABASE A-DB SET ENABLE_BROKER;
ALTER AUTHORIZATION ON DATABASE::A-DB TO [sa];
ALTER DATABASE A-DB SET TRUSTWORTHY ON;
ALTER DATABASE A-DB SET MULTI_USER;
GO

然后我创建队列和所有这些......

当我尝试发送消息时,我在 sys.transmission_queue 中看到以下错误:

在目标队列中排队消息时发生异常。错误:916,状态:3。服务器主体“sa”无法在当前安全上下文下访问数据库“MYDBNAME”。

(其中 MYDBNAME 是我们正在使用的数据库的名称)

我认为错误是由这一行引起的:

将 DATABASE::A-DB 上的授权更改为 [sa];

那可能是件坏事。但是,我可以更改授权以将其恢复到原来的状态吗?我以为它会是“dbo”,但这是不对的。是否应该将其设置为曾经创建过数据库的人?

4

2 回答 2

6

Exception - Error: 916, State: 3. The server principal "\" is not able to access the database "" under the current security context.

Error: 916, State: 3. The server principal 'sa' is not able to access the database 'xxx' under the current security context.

Resolution - Execute 'ALTER DATABASE ... SET TRUSTWORTHY ON' command. technet link

Because a database that is attached to an instance of SQL Server cannot be immediately trusted, the database is not allowed to access resources beyond the scope of the database until the database is explicitly marked trustworthy.

ALTER DATABASE MyDatabase SET TRUSTWORTHY ON

In my case, both initiator and target service were in the same db, but it was a join to an outer db that caused this error. The Alter should be written for the db in which Svc Broker is enabled.

于 2014-02-03T17:22:23.253 回答
0

因为数据库是服务器级对象,所以它需要由服务器级主体拥有。因此,您需要提供登录名才能拥有数据库。至于哪个登录名,我通常选择 sa,但它可以是您的登录名,也可以是任何其他人的登录名。

于 2013-11-04T13:27:40.787 回答