2017-01-31 40 views
0

我有两个数据库。一个带有数据,另一个带有存储过程。用户不应该直接读取数据,而只能通过存储过程读取数据。 在服务器和所有数据库上启用标志“跨数据库所有权链接”。MS SQL 2014跨数据库访问不工作,因为我期望

由于SA我做:

use data_db 
create table dbo.t(....) 
insert into t values(....) 


use sp_db 

create procedure dbo.readt as 
    select * from data_db.dbo.t 

grant execute on dbo.readt to user1 

现在我重新为USER1

execute sp_db.dbo.readt 

,我得到一个错误:

The server principal "user1" is not able to access the database "data_db" under the current security context.

我在做什么错?

回答

0

问题解决了。

我最初的愿望是,普通用户是无法在所有做“使用data_db”,因为他们不允许直接data_db读取任何数据。 显然服务器不能这样工作......奇怪,但确定。

为SA:

use data_db 
grant connect to user1 

用户现在能够做到 '使用data_db' 命令,但没有别的。 CDOC终于奏效了!

1

您需要execute as

create procedure dbo.readt 
    with execute as owner 
as 
begin 
    select * from data_db.dbo.t; 
end; 

然后,存储过程具有的权限谁创造了它,而不是调用它的用户。

0

您需要检查您的用户是否映射到您尝试登录的数据库。

相关问题