我正在使用 SSMS 10.50 访问 SQL Server 2008 R2,我对 SQL 编码非常陌生。我的登录ID是SA。我创建了一个存储过程,我想让它可由特定用户执行。但我没能做到这一点。
当我写下这些行时,
create proc GetCustomerDetailsCompanyWise
(@comp varchar(40))
as
begin
grant execute on GetCustomerDetailsCompanyWise to [sgp\deepak.b]
execute AS USER='sgp\deepak.b';
select *
from DD_Customer
where Company = @comp;
end
exec GetCustomerDetailsCompanyWise 'Google'
我收到此错误
Msg 916, Level 14, State 1, Procedure
GetCustomerDetailsCompanyWise, Line 6
The server principal "sgp\deepak.b" is not able to access the
database "TEMP" under the current security context.
您能否解释一下我可能做错了什么以及如何解决它?
最佳答案
首先创建过程
create proc GetCustomerDetailsCompanyWise
(@comp varchar(40))
as
begin
select *
from DD_Customer
where Company = @comp;
end
go
然后授予权限
grant execute on GetCustomerDetailsCompanyWise to [sgp\deepak.b];
go
然后尝试运行它。
关于sql-server - 如何使存储过程可供特定用户访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37627253/