SQL Server数据库中,如果我们忘记了sa密码,又删除了builtin\administrators帐号,我们可以用下面的方法来修复。
1、首先停止所有与SQLServer相关的服务:
- net stop "SQL Server Integration Services"
- net stop "SQL Server FullText Search (MSSQLSERVER)"
- net stop "SQL Server Agent (MSSQLSERVER)"
- net stop "SQL Server Analysis Services (MSSQLSERVER)"
- net stop "SQL Server Reporting Services (MSSQLSERVER)"
- net stop "SQL Server Browser"
- net stop "SQL Server (MSSQLSERVER)"
2、在命令行提示符下执行:
- --SQL2005
- cd C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn
- sqlservr.exe -m
如果是命名实例执行sqlservr.exe -m -s<Instance Name>
3、启动另一个命令行窗口,执行 sqlcmd -E
4、在此窗口下执行下面的命令
- create login [builtin\administrators] from windows
- go
- exec sp_addsrvrolemember [builtin\administrators], [sysadmin]
- go
- ALTER LOGIN sa WITH PASSWORD='***'
- go
- shutdown
- go
5、关闭2个命令行窗口,启动sqlserver,一切Ok
- net start "SQL Server Integration Services"
- net start "SQL Server FullText Search (MSSQLSERVER)"
- net start "SQL Server Agent (MSSQLSERVER)"
- net start "SQL Server Analysis Services (MSSQLSERVER)"
- net start "SQL Server Reporting Services (MSSQLSERVER)"
- net start "SQL Server Browser"
- net start "SQL Server (MSSQLSERVER)"
本文就介绍到这里,如果您有更好、更简单的解决方法,欢迎您与我们分享,共同发展才是硬道理。
【编辑推荐】