SQL 附加数据库时权限错误:“无法访问指定的路径”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15308671/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 14:10:12  来源:igfitidea点击:

Permissions error when attaching a database: "Cannot access the specified path"

sqlsql-serversql-server-2012adventureworks

提问by user2151027

I am running SQL Server 2012 Enterprise Edition. I have downloaded the AdventureWorks 2012 OLTP data files (both .mdfand .ldf). I saved them to the AW folder that I created in My Documentswhere I unzipped the file. I go to SQL Server Management Studio (SSMS) right-click on database, and click attach in the context menu. In the dialog I click find.

我正在运行 SQL Server 2012 企业版。我已经下载了 AdventureWorks 2012 OLTP 数据文件(包括.mdf.ldf)。我将它们保存到我在My Documents解压文件时创建的 AW 文件夹中。我转到 SQL Server Management Studio (SSMS) 右键单击​​数据库,然后单击上下文菜单中的附加。在对话框中,我单击查找。

The UI does not allow me to navigate to folder. I try typing the full path to the file, and then I get the following error:

UI 不允许我导航到文件夹。我尝试输入文件的完整路径,然后出现以下错误:

Cannot access the specified path or file on the server. Verify that you have the necessary security privileges and that the path or file exists.

无法访问服务器上的指定路径或文件。验证您是否具有必要的安全权限以及路径或文件是否存在。

I closed SSMS and restarted it, this time running as the administrator. Same bad result.

我关闭了 SSMS 并重新启动它,这次以管理员身份运行。同样糟糕的结果。

This should not be this hard. What are the exact steps to successfully attach the AdventureWorks2012 database to SSMS?

这不应该这么难。将 AdventureWorks2012 数据库成功附加到 SSMS 的确切步骤是什么?

Thanks!

谢谢!

采纳答案by peterm

Put your files to default location for Database Engine data files. If you didn't reconfigure anything it should be

将您的文件放在数据库引擎数据文件的默认位置。如果你没有重新配置任何东西应该是

\Program Files\Microsoft SQL Server\MSSQL11.<InstanceID>\MSSQL\Data

And then Attach db using SSMS.

然后使用 SSMS 附加数据库。

回答by Rogitel

Connecting to the server by Windows Authentication worked for me. I don't know if that is possible in your case.

通过 Windows 身份验证连接到服务器对我有用。我不知道在你的情况下这是否可能。

回答by PGallagher

As Rogitel says about, this could be related to how you have logged in to SSMS itself, rather than the privilege level of the application.

正如 Rogitel 所说,这可能与您登录 SSMS 本身的方式有关,而不是应用程序的权限级别。

It seems as though, if your user does not have the "sysadmin" role, then they will not have sufficient access to the filesystem on the machine in order to open the file browser.

似乎,如果您的用户没有“系统管理员”角色,那么他们将没有足够的权限访问机器上的文件系统以打开文件浏览器。

Setting aside the security concerns for one moment....

暂时搁置安全问题......

In order to grant this role;

为了授予这个角色;

  1. Log in to SSMS using Windows Authentication
  2. Navigate to Security->Logins
  3. Either double Click, or Right Click and select Properties on the user you're interested in .
  4. In the "Select a page" box, select "Server Roles"
  5. Make sure that the "sysadmin" role is selected
  6. Press Ok to save the change and close the dialog
  7. Exit SSMS
  8. Reopen SSMS and login as the User you wanted, and you should now have sufficient Privileges to browse.
  1. 使用 Windows 身份验证登录到 SSMS
  2. 导航到安全->登录
  3. 双击或右键单击并选择您感兴趣的用户的属性。
  4. 在“选择页面”框中,选择“服务器角色”
  5. 确保选择了“系统管理员”角色
  6. 按确定保存更改并关闭对话框
  7. 退出SSMS
  8. 重新打开 SSMS 并以您想要的用户身份登录,您现在应该拥有足够的权限来浏览。

回答by steoleary

It doesn't matter what permissions the account that you open the management studio has, the important account is the one that the sql server service is running as. By default it only has access to the default location specified during the install, so you can either do as the previous poster said and move your files to there, or add the service account to the permissions of the folder where you want to store your files so that it can access that location.

您打开管理工作室的帐户具有什么权限并不重要,重要的帐户是运行 sql server 服务的帐户。默认情况下,它只能访问安装期间指定的默认位置,因此您可以按照上一张海报的说明将文件移动到那里,或者将服务帐户添加到要存储文件的文件夹的权限中以便它可以访问该位置。

回答by user2854725

In my case it was related to the drives not being dependencies of the SQL Server role (Clustered Server). When I added the disks as dependencies under the SQL Server role, I could browse the drives from SSMS again.

在我的情况下,它与驱动器不是 SQL Server 角色(群集服务器)的依赖项有关。当我在 SQL Server 角色下添加磁盘作为依赖项时,我可以再次从 SSMS 浏览驱动器。

回答by Saumil

Connecting to the SQL server using the 'sa' user did the trick for me. Not everyone can have permission to do that so make sure the user you are using for SQL Authentication has all necessary privileges.

使用“sa”用户连接到 SQL 服务器对我来说很有效。并非每个人都有权这样做,因此请确保您用于 SQL 身份验证的用户具有所有必要的权限。

回答by user5766120

Just go to service in your computer and search for MSSQLSERVER restart the service by stop and start.

只需转到计算机中的服务并搜索 MSSQLSERVER 通过停止和启动重新启动服务。