I get the following error when calling a stored procedure that has a table valued parameter as one of the parameters
The EXECUTE
permission was denied on the object 'ValidationErrors'
ValidationErrors is a TVP created with the following statement:
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?
As @chiefbrownbotom says, the reason why you need execute permissions on the table type is that the table is created before (and therefore outside of) the call to the proc. To illustrate this run a SQL Profiler trace and call your proc. You will see something like this which might surprise you...
Grant Control on TYPE::schema.mytabletype to RoleOrMember
This worked for me; many thanks to @chiefbrownbotom in the comment above.
I think you may also need to grant the user permissions to the type.
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:
Update 2: To GRANT EXECUTE permissions, you'd run this in SSMS: