简体   繁体   English

使用SQL Server表值参数(TVP)作为存储过程参数需要什么权限?

[英]What permission do I need to use an SQL Server Table Valued Parameter (TVP) as a stored proc parameter?

I'm using SQL Server 2008 R2 and I've created a TVP that I want to use as a parameter to a stored proc but I get a message saying that it can't be found or I don't have permission. 我正在使用SQL Server 2008 R2并且我创建了一个TVP,我想将其用作存储过程的参数,但是我收到一条消息,说它无法找到或者我没有权限。

I can use the TVP in a script or in the body of the stored proc, but when I try to use it as a parameter I get the error. 我可以在脚本中或在存储过程的主体中使用TVP,但是当我尝试将其用作参数时,我得到了错误。

Any thoughts? 有什么想法吗?

Edit: For clarification, the error I'm getting is on the creation of the stored proc 编辑:为了澄清,我得到的错误是创建存储过程

In order for a caller to use a PROC with a table valued parameter, you'll need to (unintuitively) grant execute permissions on the TVP type to those calling the PROC ie 为了让调用者使用带有表值参数的PROC ,您需要(不直观地)将TVP类型的执行权限授予那些调用PROC

GRANT EXECUTE ON TYPE::[schema].[MyTVP] to [SomeRole]

Edit 编辑

I believe I was able to replicate the issue, viz working from a minimal set of permissions granted to a user. 我相信我能够复制这个问题,即从授予用户的最小权限集开始。 The vital step is for the DBO or Schema Owner of your TVP to grant you the following access to it, in order to be able to use it in a PROC (without this access, I was able to declare a loose variable of the TVP type, but not use it in a PROC). 至关重要的一步是让您的TVP的DBO或Schema所有者授予您以下访问权限,以便能够在PROC使用它(没有此访问权限,我能够声明TVP类型的松散变量,但不能在PROC中使用它)。

GRANT REFERENCES ON TYPE::[schema].[MyTVP] to YOURROLE -- Or User.

Grant Reference here (Obviously you'll also need CREATE PROCEDURE permission, plus relevant access to any objects used in the PROC) Grant Reference (显然你也需要CREATE PROCEDURE权限,以及对PROC中使用的任何对象的相关访问权限)

Consumers of the PROC will need to also have the GRANT EXECUTE permission on the Proc and on the Type as per the initial answer. PROC的消费者还需要根据初始答案对Proc和Type进行GRANT EXECUTE许可。

Right click on your table valued funtion that you want to grant access. 右键单击要授予访问权限的表值函数。 Take the properties from the context menu. 从上下文菜单中获取属性。

1) Click on "Permissions" tab on the right. 1)单击右侧的“权限”选项卡。

2) Browse to the user name (SQL or Windows). 2)浏览到用户名(SQL或Windows)。

3) Select that user. 3)选择该用户。

4) Under Explicit Permissions section at the bottom select Grant for Control Permissions click OK. 4)在底部的Explicit Permissions部分下,选择Grant for Control Permissions,单击OK。

5) click OK 5)单击“确定”

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM