SQL 数据库 [dbName] 不可访问。(对象浏览器)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14123917/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The database [dbName] is not accessible. (ObjectExplorer)
提问by greg
I have an issue in regards to using SQL Server 2008 R2.
我在使用 SQL Server 2008 R2 时遇到问题。
I recently had an issue with my computer and therefore I had to reboot windows and had to grant permission from one user to another user (using the security feature in the properties). When giving permission initially though, it through a "Access Denied" message.
我最近遇到了我的计算机问题,因此我不得不重新启动 Windows,并且不得不将一个用户的权限授予另一个用户(使用属性中的安全功能)。最初授予权限时,它会通过“拒绝访问”消息。
After much research, it stopped producing this error (the user which I needed to grant permission too wasn't available), which then caused another issue to occur, but this time within SQL Server. It produces this message;
经过大量研究,它停止产生此错误(我也需要授予权限的用户不可用),然后导致另一个问题发生,但这次是在 SQL Server 中。它产生这个消息;
The database [dbName] is not accessible. (ObjectExplorer)
数据库 [dbName] 不可访问。(对象浏览器)
This error occurs when I try to select the drop down option to see the list of tables and stored procedures of the database within SQL Server. I found an explanation for this on the following link;
当我尝试选择下拉选项以查看 SQL Server 中数据库的表和存储过程列表时,会发生此错误。我在以下链接中找到了对此的解释;
And I then tried to implement like so;
然后我尝试像这样实现;
USE msdb;
GO
GRANT CONNECT TO [DBName\MyName] ;
CREATE DATABASE [DBNAME] ON PRIMARY
Using a script I created (luckily before this problem occurred) it through a whole lot of messages;
使用我创建的脚本(幸运的是在此问题发生之前)它通过大量消息;
Msg 15151, Level 16, State 1, Line 1
Cannot find the user 'DBName\MyName', because it does not exist or you do not have permission.
Msg 262, Level 14, State 1, Line 2
CREATE DATABASE permission denied in database 'master'.
Msg 5011, Level 14, State 9, Line 1
User does not have permission to alter database 'DBName', the database does not exist, or the database is not in a state that allows access checks.
Msg 5069, Level 16, State 1, Line 1 ...
消息 15151,级别 16,状态 1,第 1 行
找不到用户“DBName\MyName”,因为它不存在或您没有权限。
消息 262,级别 14,状态 1,第 2 行
CREATE DATABASE 权限在数据库“master”中被拒绝。
消息 5011,级别 14,状态 9,第 1 行
用户无权更改数据库“DBName”、数据库不存在或数据库未处于允许访问检查的状态。
消息 5069,级别 16,状态 1,第 1 行 ...
After this bunch of errors, I have become unstuck and therefore would much be grateful if anyone could give me some feedback in regards to what I could do to resolve this issue. Cheers.
在出现这一系列错误之后,我已经陷入困境,因此如果有人能给我一些关于我可以做些什么来解决这个问题的反馈,我将不胜感激。干杯。
采纳答案by Ben
Generally it is a bad idea to grant permissions directly to logins. You should create role objects in the database, and all permissions in the database should be assigned to the roles.
通常,直接向登录授予权限是一个坏主意。您应该在数据库中创建角色对象,并将数据库中的所有权限分配给角色。
Then when moving the database to another computer (or reinstalling) the only things you have to modify are server logins and role assignments.
然后,当将数据库移动到另一台计算机(或重新安装)时,您唯一需要修改的是服务器登录名和角色分配。
回答by Samson M. Adeyemo
Login with sa and expand Security > Login, right click on the username and then properties, Click User Mapping and select the DB you want the user to access and then Ok
使用 sa 登录并展开安全 > 登录,右键单击用户名,然后单击属性,单击用户映射并选择您希望用户访问的数据库,然后确定
回答by Yasmine GreenApple
One possible problem is that you have two instances of the database, so you have to deactivate one instance, if you have your database opened and accessible in your server explorer in Visual studio
close connexion then go to windows services and stop and restart SQL server service (MSSQL)
then go to Management studio
and open your database, it should be opened and you can explore tables from Management studio.
一个可能的问题是您有两个数据库实例,因此您必须停用一个实例,如果您在服务器资源管理器中打开并在Visual studio
关闭连接中访问您的数据库,然后转到 Windows 服务并停止并重新启动,SQL server service (MSSQL)
然后转到Management studio
并打开您的数据库,它应该被打开,您可以从管理工作室探索表。
回答by user3259669
Seems the database you are trying to access do not have admin privileges. Close SSMS and open it by Run as Administrator.
您尝试访问的数据库似乎没有管理员权限。关闭 SSMS 并通过以管理员身份运行打开它。