SQL Server 2008 R2 Express 权限 - 无法创建数据库或修改用户

发布于 2025-01-03 14:43:04 字数 901 浏览 0 评论 0原文

最近刚刚升级到 SQL Server 2008 R2 Express。当我使用 Windows 身份验证以我的 id myuser 登录后尝试创建数据库时,我收到此错误:

执行 Transact-SQL 语句或批处理时发生异常。 (Microsoft.SqlServer.ConnectionInfo)
数据库“master”中的 CREATE DATABASE 权限被拒绝。 RESTORE HEADERONLY 异常终止错误 262

如果我尝试将 sysadmin 角色添加到 myuser,这是我收到的错误:

为 ServerRole“sysadmin”添加成员失败。 (微软.SqlServer.Smo)
执行 Transact-SQL 语句或批处理时发生异常。 (Microsoft.SqlServer.ConnectionInfo)
用户无权执行此操作错误 15247

如果我尝试使用 T-SQL 使用此命令将此角色添加到我的用户,

EXEC sp_addsrvrolemember 'ziffenergy\myuser', 'sysadmin';
GO

这是我收到的错误:

消息 15247,级别 16,状态 1,过程 sp_addsrvrolemember,第 29 行
用户无权执行此操作。

有人有什么建议吗?看来我无法对本地计算机上的数据库执行任何操作。请注意,我是正在使用的 Windows 7 工作站的管理员,如果我尝试使用 SQL Server Management Studio 在我们的网络 IT 测试数据库服务器上创建或修改数据库和/或用户,我可以毫无问题地做到这一点。

Recently just upgraded to SQL Server 2008 R2 Express. When I attempt to create a database after logging in using Windows Authentication with my id myuser I receive this error:

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
CREATE DATABASE permission denied in database 'master'. RESTORE HEADERONLY is terminating abnormally Error 262

If I try to add the sysadmin role to myuser, this is the error I receive:

Add member failed for ServerRole 'sysadmin'. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
User does not have permission to perform this action Error 15247

If I try to add this role to my user with T-SQL, using this command,

EXEC sp_addsrvrolemember 'ziffenergy\myuser', 'sysadmin';
GO

Here is the error I receive:

Msg 15247, Level 16, State 1, Procedure sp_addsrvrolemember, Line 29
User does not have permission to perform this action.

Does anyone have any suggestions? It seems that I can't do anything with database on the local machine. Please note that I am the administrator on the Windows 7 workstation I am using, and if I try to create or modify databases and/or users on our network IT Test database server using SQL Server Management Studio, I can do that with no problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

清晰传感 2025-01-10 14:43:04

来晚了,但我发现这个 非常棒如果您没有 sa 密码,则可以了解如何控制 SQLExpress 实例的分步指南。我使用此过程不仅重置了我的 sa 密码,而且还将我的域帐户添加到了所有可用的服务器角色中。我现在可以使用正常登录创建数据库、更改登录、执行批量操作、备份/恢复等。

总而言之,您可以使用 SQL Server 配置管理器将实例置于单用户模式。当您连接时,这会将您提升为系统管理员,使您能够设置一切。

编辑:我已经复制了以下步骤 - 感谢上面链接的原作者。

  1. 以管理员身份(或任何具有管理员权限的用户)登录计算机
  2. 打开“SQL Server 配置管理器”
  3. 单击左侧窗格中的“SQL Server 服务”
  4. 如果出现以下情况,则停止右侧窗格中的“SQL Server”和“SQL Server 代理”实例它正在运行
  5. 通过右键单击“SQL Server”实例 -> 以单用户模式运行 SQL Express ->属性(在 SQL Server 配置管理器的右侧窗格中)。
  6. 单击“高级”选项卡,然后查找“启动参数”。更改“启动参数”,使新值为-m; (没有<>)
    例子:
    来自:-dc:\Program Files\Microsoft SQL........................(直到字符串结尾)
    到:-m;-dc:\Program Files\Microsoft SQL........(直到字符串结尾)
  7. 启动 SQL Server
  8. 打开 MS SQL Server Management Studio 并登录到 SQL使用“Windows 身份验证”作为身份验证模式的服务器。由于我们的 SQL Server 在单用户模式下运行,并且您以管理员权限登录到计算机,因此您将拥有对数据库的“sysadmin”访问权限。
  9. 展开左侧窗格中 MS SQL Server Management Studio 上的“安全”节点
  10. 展开“登录”节点
  11. 双击“sa”登录
  12. 如果勾选了“强制密码策略”,则通过输入复杂密码来更改密码,否则,只需输入任意密码。
  13. 单击左侧窗格中的“状态”,确保“sa”帐户已“启用”。将“登录”下的单选框设置为“已启用”
  14. 单击“确定”
  15. 返回 MS SQL Server Management Studio 的主窗口,通过右键单击左窗格中最顶部的节点(通常为“ .\SQLEXPRESS (SQL Server )") 并选择属性。
  16. 单击左窗格中的“安全”,并确保“服务器身份验证”下选择“SQL Server 和 Windows 身份验证模式”
  17. 单击“确定” 断开
  18. 与 MS SQL Server Management Studio 的连接
  19. 再次打开“Sql Server 配置管理器”并停止SQL Server 实例。
  20. 右键单击 SQL Server 实例,然后单击“高级”选项卡。再次查找“启动参数”并删除“-m;”您之前添加的。
  21. 单击“确定”并再次启动 SQL Server 实例
  22. 您现在应该能够使用在步骤 12 中设置的新密码以“sa”身份登录。

Coming late to the party, but I found this fantastic step-by-step guide on getting control of your SQLExpress instance if you don't have your sa password. I used this process to not only reset my sa password, but I also added my domain account to all the available server roles. I can now create databases, alter logins, do bulk operations, backups/restores, etc using my normal login.

To summarize, you use SQL Server Configuration Manager to put your instance into single-user mode. This elevates you to sysadmin when you connect, allowing you the ability to set everything up.

Edit: I've copied the steps below - kudos to the original author of the link above.

  1. Log on to the computer as an Administrator (or Any user with administrator privileges)
  2. Open "SQL Server Configuration Manager"
  3. Click "SQL Server Services" on the left pane
  4. Stop "SQL Server" and "SQL Server Agent" instance on the right pane if it is running
  5. Run the SQL Express in single-user mode by right clicking on "SQL Server" instance -> Properties (on the right pane of SQL Server Configuration Manager).
  6. Click Advanced Tab, and look for "Startup Parameters". Change the "Startup Parameters" so that the new value will be -m; (without the <>)
    example:
    from: -dc:\Program Files\Microsoft SQL.............(til end of string)
    to: -m;-dc:\Program Files\Microsoft SQL.............(til end of string)
  7. Start the SQL Server
  8. Open your MS SQL Server Management Studio and log on to the SQL server with "Windows Authentication" as the authentication mode. Since we have the SQL Server running on single user mode, and you are logged on to the computer with Administrator privileges, you will have a "sysadmin" access to the database.
  9. Expand the "Security" node on MS SQL Server Management Studio on the left pane
  10. Expand the "Logins" node
  11. Double-click the 'sa' login
  12. Change the password by entering a complex password if "Enforce password policy" is ticked, otherwise, just enter any password.
  13. Make sure that "sa" Account is "enabled" by clicking on Status on the left pane. Set the radio box under "Login" to "Enabled"
  14. Click "OK"
  15. Back on the main window of MS SQL Server Management Studio, verify if SQL Server Authentication is used by right clicking on the top most node in the left pane (usually ".\SQLEXPRESS (SQL Server )") and choosing properties.
  16. Click "Security" in the left pane and ensure that "SQL Server and Windows Authentication mode" is the one selected under "Server authentication"
  17. Click "OK"
  18. Disconnect from MS SQL Server Management Studio
  19. Open "Sql Server Configuration Manager" again and stop the SQL Server instance.
  20. Right-click on SQL Server instance and click on "Advanced" tab. Again look for "Startup Parameters" and remove the "-m;" that you added earlier.
  21. Click "OK" and start the SQL Server Instance again
  22. You should now be able to log on as "sa" using the new password that you have set in step 12.
春夜浅 2025-01-10 14:43:04

您可能是工作站的管理员,但这对 SQL Server 来说毫无意义。您的登录名必须是 sysadmin 角色的成员才能执行相关操作。默认情况下,本地管理员组不再添加到 SQL 2008 R2 中的 sysadmin 角色。您需要使用其他名称(例如 sa)登录才能授予自己权限。

You may be an administrator on the workstation, but that means nothing to SQL Server. Your login has to be a member of the sysadmin role in order to perform the actions in question. By default, the local administrators group is no longer added to the sysadmin role in SQL 2008 R2. You'll need to login with something else (sa for example) in order to grant yourself the permissions.

z祗昰~ 2025-01-10 14:43:04

在 SSMS 2012 中,您必须使用:

要启用单用户模式,在 SQL 实例属性中,不要转到“高级”标签,已经有一个“启动参数”标签。

  1. 添加“-m;”进入参数;
  2. 重新启动服务并使用Windows身份验证登录此SQL实例;
  3. 其余步骤与上面相同。在安全中更改您的 Windows 用户帐户权限或重置 SA 帐户密码。
  4. 最后,将“启动参数”中的“-m”参数去掉;

In SSMS 2012, you'll have to use:

To enable single-user mode, in SQL instance properties, DO NOT go to "Advance" tag, there is already a "Startup Parameters" tag.

  1. Add "-m;" into parameters;
  2. Restart the service and logon this SQL instance by using windows authentication;
  3. The rest steps are same as above. Change your windows user account permission in security or reset SA account password.
  4. Last, remove "-m" parameter from "startup parameters";
倚栏听风 2025-01-10 14:43:04

我按照killthrush的答案中的步骤进行操作,令我惊讶的是它不起作用。以 sa 身份登录,我可以看到我的 Windows 域用户,并使他们成为系统管理员,但是当我尝试使用 Windows 身份验证登录时,我在登录名下看不到我的登录信息,无法创建数据库等。然后它击中了我。 该登录可能与另一个同名的域帐户(具有某种不正确的内部/隐藏 ID)相关联。我不久前离开了这个组织,几个月后又回来了。他们没有重新激活我的旧帐户(他们可能已删除),而是创建了一个具有相同域\用户名和新内部 ID 的新帐户。使用 sa 我删除了旧的登录名,使用相同的名称重新添加它并添加了 sysadmin。我使用 Windows Auth 重新登录,一切看起来都正常。我现在可以查看我的登录信息(和其他登录信息),并且可以使用 Windows 身份验证登录信息执行作为系统管理员所需执行的任何操作。

I followed the steps in killthrush's answer and to my surprise it did not work. Logging in as sa I could see my Windows domain user and had made them a sysadmin, but when I tried logging in with Windows auth I couldn't see my login under logins, couldn't create databases, etc. Then it hit me. That login was probably tied to another domain account with the same name (with some sort of internal/hidden ID that wasn't right). I had left this organization a while back and then came back months later. Instead of re-activating my old account (which they might have deleted) they created a new account with the same domain\username and a new internal ID. Using sa I deleted my old login, re-added it with the same name and added sysadmin. I logged back in with Windows Auth and everything looks as it should. I can now see my logins (and others) and can do whatever I need to do as a sysadmin using my Windows auth login.

你与清晨阳光 2025-01-10 14:43:04

我的 Windows 计算机上有 2 个帐户,其中一个帐户遇到了此问题。我不想使用 sa 帐户,我想使用 Windows 登录。对我来说,我需要简单地登录到用于安装 SQL Server 的另一个帐户,然后从那里添加新帐户的权限

(SSMS > 安全 > 登录 > 添加登录)

获取完整域名的简单方法是在打开的 cmd echo 中添加每个域名。

echo %userdomain%\%username%

为该用户添加登录名,并为其授予 master 数据库和您想要的其他数据库的所有权限。当我说“所有权限”时,请确保不要检查任何“拒绝”权限,因为这会起到相反的作用。

I have 2 accounts on my windows machine and I was experiencing this problem with one of them. I did not want to use the sa account, I wanted to use Windows login. It was not immediately obvious to me that I needed to simply sign into the other account that I used to install SQL Server, and add the permissions for the new account from there

(SSMS > Security > Logins > Add a login there)

Easy way to get the full domain name you need to add there open cmd echo each one.

echo %userdomain%\%username%

Add a login for that user and give it all the permissons for master db and other databases you want. When I say "all permissions" make sure NOT to check of any of the "deny" permissions since that will do the opposite.

因为看清所以看轻 2025-01-10 14:43:04

我遇到了同样的问题,直到我发现这个
我打开一个新查询并运行以下命令

RESTORE DATABASE <YourDatabase> 
FROM DISK='<the path to your backup file>\<YourDatabase>.bak'

,然后右键单击“数据库”-> 恢复数据库 ->选择设备 ->单击... -> 添加您的数据集 ->点击确定

I got the same problem till I found this.
I open a new query and run the following

RESTORE DATABASE <YourDatabase> 
FROM DISK='<the path to your backup file>\<YourDatabase>.bak'

then right-click on Databases -> Restore Database -> select Device -> click ... -> ADD your dataset -> Click Ok

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文