English 中文(简体)
存储过程中的表值参数出现执行权限被拒绝的错误。
原标题:Table valued parameter in a stored procedure gets execute permissions denied error

当调用一个存储过程时,如果一个参数是表值参数,则会出现以下错误。

EXECUTE> >在标的上被拒批

ValidationErrors是通过以下语句创建的TVP:

CREATE TYPE [dbo].[ValidationErrors] AS TABLE(
    [ErrorMessage] [varchar](255) NOT NULL
)

The user executing the stored procedure has execute privileges on the stored procedure. However, I still get the above error. Any ideas?

最佳回答

我认为您也需要授予用户对该类型的权限。

References for GRANTing permissions to types:
SQL 2005
SQL 2008

Update:
Re: why you have to grant permissions on the type when you have permissions on the sproc. I don t know the definitive reason, but BOL says:

Unlike user-defined types created by using sp_addtype, the public database role is not automatically granted REFERENCES permission on types that are created by using CREATE TYPE. This permission must be granted separately.

Update 2: To GRANT EXECUTE permissions, you d run this in SSMS:

GRANT EXECUTE ON TYPE::dbo.ValidationErrors TO SomeUser;
问题回答

@chiefbrownbotom说,你为什么需要在表格类型上执行许可,原因是表格是在(因此不在)向原方发出呼吁之前制作的。 为说明这一活动,请您介绍。 你们会看到这样的情况,这可能会使你们感到惊讶。

DECLARE @p1 TABLE AS YourTableType
INSERT INTO @p1 (col1, col2, col3) VALUES ( val1 , val2 , val3 )
INSERT INTO @p1 (col1, col2, col3) VALUES ( val1 , val2 , val3 )
...
EXEC usp_YourStoredProc @p1

授予角色或成员对TYPE::schema.mytabletype的控制权限。

这对我有用;非常感谢上面评论中的@chiefbrownbotom。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签