SQL Server用户登录失败

SQL Server数据库中,如果我们忘记了 sa密码,又删除了jhyf-kj\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、在命令行提示符cmd下执行:(这个地址不确定喔 .windowsXP和windows7下不一样的)
cd C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn 
sqlservr.exe -m  
注:如果是命名实例执行sqlservr.exe -m -s(一般不用)
 
3、启动另一个命令行提示符cmd,执行 sqlcmd -E
4、在此窗口下执行下面的命令
create login [jhyf-kj\administrators] from windows 
go 
exec sp_addsrvrolemember [jhyf-kj\administrators], [sysadmin] 
go  
ALTER LOGIN sa WITH PASSWORD='123456' 
go
shutdown 
go 
注:jhyf-kj 即计算机名


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)"

你可能感兴趣的:(SQL,Server)