简体   繁体   English

SQL Server数据库:找不到明显存在的对象

[英]SQL Server database: Can't find an object which clearly exists

EDIT: How to give exec permissions to a user defined type? 编辑:如何给用户定义类型的exec权限?

Looks like "Bug2" is a user defined type. 看起来“ Bug2”是用户定义的类型。

select * from sys.types
where is_user_defined = 1 and name = 'Bug2'

Now to get rid of this error: 现在摆脱这个错误:

"The EXECUTE permission was denied on the object 'Bug2', database 'abc', schema 'dbo'" “对对象'Bug2',数据库'abc',模式'dbo'的EXECUTE权限被拒绝”

What command should I be using? 我应该使用什么命令?


I'm just playing around with someone else's code and bumped into this: 我只是在玩别人的代码,碰到了这个:

If I do 如果我做

DECLARE @bugList Bug2

SELECT * 
FROM @bugList

Then I'm getting results 然后我得到结果

But if I do 但是如果我这样做

SELECT * 
FROM Bug2

Then I get a 然后我得到一个

Invalid object name 'Bug2'. 无效的对象名称“ Bug2”。

What is going on here? 这里发生了什么?

Basically I'm trying to run a stored procedure which uses this "Bug2" and since there is some permission issue I'm getting this error on running it: 基本上,我试图运行一个使用此“ Bug2”的存储过程,并且由于存在一些权限问题,因此我在运行它时遇到此错误:

The EXECUTE permission was denied on the object 'Bug2', database 'abc', schema 'dbo'. 对对象“ Bug2”,数据库“ abc”,模式“ dbo”的EXECUTE权限被拒绝。

So all I want to do is: 所以我要做的就是:

GRANT EXEC ON Bug2 TO PUBLIC

But SQL Server is not able to find this object "Bug2" and therefore throws an error. 但是SQL Server找不到该对象“ Bug2”,因此引发错误。

Can anyone help? 有人可以帮忙吗?

Ok. 好。 Got it working using this: 使用此工具可以正常工作:

GRANT EXECUTE ON TYPE::Bug2 to PUBLIC

Thanks! 谢谢!

Instead of using sys.types use sys.objects . 不用sys.types而是使用sys.objects If Bug2 is a table then query looks like: 如果Bug2是一个表,则查询如下所示:

SELECT * FROM sys.objects WHERE name='Bug2' AND type='U'

It's a user-defined table type (typically used for table-valued parameters). 这是用户定义的表类型 (通常用于表值参数)。 Look in db_nm > programmability > types > user-defined table types and you'll see a bug2 object. 查看db_nm>可编程性>类型>用户定义的表类型,您将看到一个bug2对象。 You can address the permissions issue on that object (via script or GUI). 您可以解决该对象上的权限问题(通过脚本或GUI)。

Script Option: 脚本选项:

use [abc]
GO
GRANT EXECUTE ON TYPE::[dbo].[bug2] TO [public]

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

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