简体   繁体   English

SQL Server 2008 - 删除默认用户后添加Windows帐户

[英]SQL Server 2008 - Add Windows Account After Deleting Default User

This is rather embarrassing, but I accidentally deleted my Windows account from the list of SQL Server 2008 users and I cannot for the life of me figure out how to re-add myself now that I don't have login privileges. 这是相当尴尬的,但我不小心从SQL Server 2008用户列表中删除了我的Windows帐户,我不能为我的生活找出如何重新添加自己,因为我没有登录权限。

The server is running on my machine and the only other Windows users with access are IUSR, NETWORK SERVICE and SYSTEM. 服务器在我的机器上运行,只有其他具有访问权限的Windows用户是IUSR,NETWORK SERVICE和SYSTEM。 Is there anything I can do short of re-installing? 有什么我可以做的没有重新安装?

I also recently deleted my windows account from my local development 2008 server. 我最近还从我的本地开发2008服务器上删除了我的Windows帐户。 I was able to use SQL server's Single User Mode to recreate my login and add it to the sysadmin role. 我能够使用SQL Server的单用户模式重新创建我的登录并将其添加到sysadmin角色。 It took just a few minutes, and I didn't have to admit my terrible error to anyone. 只用了几分钟,我就不必向任何人承认我的可怕错误。

From MSDN: 来自MSDN:

Starting SQL Server in single-user mode enables any member of the computer's local Administrators group to connect to the instance of SQL Server as a member of the sysadmin fixed server role. 以单用户模式启动SQL Server使计算机的本地Administrators组的任何成员都可以作为sysadmin固定服务器角色的成员连接到SQL Server实例。

Here's how I reinstated myself: 这是我恢复自己的方式:

  1. Exit out of SSMS 退出SSMS
  2. Stop any SQL related services. 停止任何SQL相关服务。 I had to stop Reporting Services. 我不得不停止Reporting Services。 Other SQL services such as SQL Agent will also use up your one, valuable connection. 其他SQL服务(如SQL Agent)也会耗尽您的一个有价值的连接。
  3. Stop the SQL service 停止SQL服务
  4. Start the SQL service with the extra parameter -m . 使用额外参数-m启动SQL服务。 This will put the SQL into Single User Mode. 这将使SQL进入单用户模式。 This means that SQL will only accept one connection. 这意味着SQL只接受一个连接。
  5. Use sqlcmd to connect to your server with the -E trusted connection option. 使用sqlcmd通过-E trusted connection选项连接到您的服务器。 SQL will accept you into the sysadmin role if you're a local administrator. 如果您是本地管理员,SQL将接受您进入sysadmin角色。
  6. In the interactive session, create your login and add to the sysadmins role. 在交互式会话中,创建登录名并添加到sysadmins角色。

     USE master GO CREATE LOGIN [domain\\username] FROM WINDOWS WITH DEFAULT_DATABASE=[Master] GO EXEC sp_addsrvrolemember @loginame=N'domain\\username', @rolename=N'sysadmin' GO 
  7. Stop the SQL service, remove the -m parameter and restart the service. 停止SQL服务,删除-m参数并重新启动服务。 You should now be able to go back into SSMS and continue using the server normally. 您现在应该可以返回SSMS并继续正常使用服务器。

If you get the message: 如果你收到消息:

Login failed for user 'domain\\username'. 用户'domain \\ username'登录失败。 Reason: Server is in single user mode. 原因:服务器处于单用户模式。 Only one administrator can connect at this time. 此时只能有一个管理员连接。

Then there is something using your single connection. 然后有一些使用你的单一连接。 You'll need to find that service or connection and stop it before you can log in. Check SQL Agent, SQL Reporting Services, SQL Analysis Services etc. 您需要找到该服务或连接并在登录之前将其停止。检查SQL代理,SQL Reporting Services,SQL Analysis Services等。

Luckily, this wasn't too hard to fix (not that it should have been hard...)! 幸运的是,这并不难解决(不是说应该很难......)!

This blog post explains the steps for starting SQL Server in Single User Mode, which (for some reason) allowed me to login as my Windows administrator account, add the account to the user list (with CREATE LOGIN), enable the SA user and set its password to something I actually knew, and finally login as SA and give the Windows account sysadmin privileges. 此博客文章 介绍了在单用户模式下启动SQL Server的步骤,由于某种原因,这允许我以Windows管理员帐户登录,将帐户添加到用户列表(使用CREATE LOGIN),启用SA用户并设置它的密码是我实际知道的东西,最后以SA身份登录并授予Windows帐户sysadmin权限。

Edit 07/05/13: Try this link instead . 编辑07/05/13: 请尝试使用此链接

Often SQL Server is installed so that any any local administrator is a SQL Server sysadmin . 通常安装SQL Server,以便任何本地管理员都是SQL Server sysadmin

If this is your case you can run Management Studio as administrator and then add any other windows user as a login in the Security section. 如果是这种情况,您可以以管理员身份运行Management Studio,然后在“安全性”部分中将任何其他Windows用户添加为登录名。

This solution worked for me. 这个解决方案对我有用。

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

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