Domyślnie lokalny administrator lub administrator domeny nie jest administratorem w SQL Server, dlatego jeżeli usunąłeś „jakoś” jedyne konto administratora to masz problem, ale…
Jeżeli jesteś lokalnym administratorem, to możesz wyłączyć serwer. Możesz go także uruchomić w trybie single user. Jeśli lokalny admin zaloguje się do serwera w trybie single user to z marszu jest przypisany do roli sysadmin, czyli jest administratorem i może stworzyć nowy login administratora.
Poniższe rozwiązanie pochodzi ze strony: http://stackoverflow.com/questions/1528538/sql-server-2008-add-windows-account-after-deleting-default-user ale przeklejam je tutaj „dla potomnych”.
From 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.
Here’s how I reinstated myself:
- Exit out of SSMS
- Stop any SQL related services. I had to stop Reporting Services. Other SQL services such as SQL Agent will also use up your one, valuable connection.
- Stop the SQL service
- Start the SQL service with the extra parameter
-m
. This will put the SQL into Single User Mode. This means that SQL will only accept one connection. - Use
sqlcmd
to connect to your server with the-E
trusted connection option. SQL will accept you into thesysadmin
role if you’re a local administrator. - In the interactive session, create your login and add to the
sysadmins
role.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
- Stop the SQL service, remove the
-m
parameter and restart the service. You should now be able to go back into SSMS and continue using the server normally.
Komentarze:
http://www.mssqltips.com/sqlservertip/2682/recover-access-to-a-sql-server-instance/