简体   繁体   English

用户无权访问数据库

[英]User does not have permission to access a database

I'm trying to connect to a database using Windows Authentication. 我正在尝试使用Windows身份验证连接到数据库。 I believe that my current user does not have access to it. 我相信我当前的用户无法访问它。

How can I enable a user to login to SQL Server, and use the database? 如何让用户登录到SQL Server并使用数据库?

You need to use the SQL Server Management Studio program to grant access for the user. 您需要使用SQL Server Management Studio程序为用户授予访问权限。 You'll need to connect in with a login that has administration privileges for the database. 您需要使用具有数据库管理权限的登录名进行连接。 If you have don't have those privileges you'll need to contact someone that does. 如果您没有这些特权,则需要联系有此特权的人。

If you do have a login with those privileges: 如果您确实拥有具有这些权限的登录信息:

  • open Management Studio 打开Management Studio
  • connect to the database server the database is on and look for the Security node in Object Explorer. 连接到数据库所在的数据库服务器,并在对象资源管理器中查找安全性节点。
  • Expand the Security node and look for the name of the user in the list of Logins. 展开“安全性”节点,然后在“登录”列表中查找用户的名称。 The user's name should be the same as the user's Windows login if you are using Windows Authentication DOMAIN\\Username format . 如果您使用Windows身份验证DOMAIN\\Username format ,则用户的名称应与用户的Windows登录名相同。
  • If the user is there, you will need to grant that user appropriate permissions to the database (read, execute SPs, etc.). 如果用户在那里,您将需要向该用户授予对数据库的适当权限(读取,执行SP等)。
  • If the user isn't there you will need to add them. 如果用户不在那里,您将需要添加它们。

Permission can also be added by group so you should check for groups that the user belongs to as well. 权限也可以按组添加,因此您应该检查用户所属的组。

I had a scenario where I inherited a PC from another developer that left the organization. 我有一个场景,我从另一个离开组织的开发人员那里继承了一台PC。 I couldn't access the default instance using Windows Authentication. 我无法使用Windows身份验证访问默认实例。

Here was the solution: 这是解决方案:

  1. Open up SQL Server Configuration Manager 打开SQL Server配置管理器
  2. Click on "SQL Server Services" 单击“SQL Server服务”
  3. Locate the Instance in the right pane and double-click for its properties 在右窗格中找到实例,然后双击其属性
  4. In the "Log On" tab, notice the "Log on as:" radio button option is set to "Built-in account". 在“登录”选项卡中,注意“登录为:”单选按钮选项设置为“内置帐户”。
  5. Change the option to "This account" and add your Windows Authentication account with your domain and username and enter your password. 将选项更改为“此帐户”,并使用您的域和用户名添加Windows身份验证帐户,然后输入您的密码。
  6. Click "Apply". 单击“应用”。 Click "Yes" when it asks you if you want to restart the instance. 当它询问您是否要重新启动实例时,单击“是”。

This will automatically add your Windows Authentication user account (Active Directory or local user) to the SQL Server instance. 这将自动将您的Windows身份验证用户帐户(Active Directory或本地用户)添加到SQL Server实例。 You will now be able to connect right away to the selected instance. 您现在可以立即连接到所选实例。 As best practice, reset the settings back to the Built-in user account (most likely Network Service). 最佳做法是将设置重置为内置用户帐户(最可能是网络服务)。

That's it! 而已!

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

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