Question:
Built-in
administrators account was accidentally removed and you don't have the
SA password. If you are a member of the Administrators group in your
machine and built-in administrators has no access to the database you
can not connect to the database using the SQL Server Management Studio
unless you will login using valid SQL Server account or impersonating
other account using Run As option when you right click the shortcut.
Answer:
To recover the account follow these steps
- Open SQL Server Configuration Manager (Programs -> Microsoft SQL Server 200X -> Configuration Tools).
- Select SQL Server Services node.
- Select the instance of SQL Server you want to recover.
- Right click the instance and select Properties from the context menu.
- On Properties form, select Advanced Tab.
- Look
for Startup Parameters and add "-m;" at the beginning. Make sure that
there is no space between the semi-colon and the next set of
parameters.
- Click Apply button.
- Click Ok button.
- Stop-Start the SQL Server instance.
- After SQL Server instance starts Windows Administrator can now access SQL Server using SQL command (sqlcmd). Be sure that your account is a member of Administrators group of the machine or domain.
- Go to Start -> Run and type "cmd" then click Run button to launch the command prompt.
- On the Command Prompt type "sqlcmd" and press enter. It will then move the cursor next to "1>". If your server is not the default database server you need to type "sqlcmd -S MACHINENAME\INSTANCENAME" just replace the MACHINENAME with your computer name and INSTANCENAME with your SQL Server instance name.
- Type "EXEC sp_addsrvrolememeber 'BUILTIN\Administrators', 'sysadmin';" then press enter. This will gives the built-in administrators system administor role to the database.
- Type "GO".
- Type "exit" to exit the SQL Command.
- After successfully restoring the BUILTIN\Administrators privilege. Repeat step 1-9 but on step 6 remove the "-m;" we added previously.
This works on both SQL Server 2005 and SQL Server 2008.
Warning:
Please consult your action with the System Administrator and test it in
a controlled environment before implementing it to production.
"Login Failed for user 'MACHINENAME\Administrators'. Reason: Server is in single user mode. Only one administrator can connect at this time."
This error is raised when you login using sqlcmd in step 12.
When
we added "-m;" in step 6 we force the SQL Server to run in Single-user
Mode. In this mode only one user is allowed to access the database
server at a given time. Follow these steps to fix the error.
- Open SQL Server Configuration Manager.
- Select the SQL Services node.
- Stop all services (Reporting Service, Analysis Service, and SQL Server Agent) with the same instance with the SQL Server you want to recover. Keep SQL Server service alive.
- Repeat step 12.
After successfully restoring the account Start all the services we stopped in Step 3.
Adding Windows User while in Single-User Mode
Make
sure that the account you use to login to the machine is a member of
Administrators group. This also happen if the user has no access to the
database. To add Windows user to the database follow these steps.
- After successfully logged-in in Step 12 of the Solution, type "CREATE LOGIN [DOMAIN\username] FROM WINDOWS;". This action will add the Windows User to database Security Logins.
- Type "GO".
- Type "EXEC sp_addsrvrolemember 'DOMAIN\username', 'sysadmin';". This action will give the user the sysadmin role.
- Type "GO"
- Type "exit" to exit SQL command.
No comments:
Post a Comment