How to reset lost SA password in SQL Express
Overview
If you ever find yourself in a situation where you need to reset the sa password on a SQL Express instance then you are not alone. I recently inherited a PC from a previous developer that already had SQL Express installed. This normally wouldn’t be a bad thing, except in this case it was not setup in mixed mode and my logged in account had no sysadmin rights on the instance.
In this article I hope to enlighten you as to how to reset the sa password in SQL Express without having any sort of administrator rights to the SQL instance.
You will need to be somewhat comfortable with editing the registry, starting and stopping windows services and working with a command prompt.
Steps to SQL Express sysadmin access
In order to gain sysadmin access to the SQL instance there were a few things that I needed to accomplish. Here is the basic goals I needed to achieve:
- Change the login method from Windows Authentication to Mixed mode
- Enable the sa user account
- Reset the password to the sa user account
Doesn’t seem like that daunting of a list does it? I didn’t think so either.
Change the login method
In order to change the login method I had to change a registry setting. Why, you ask? Because, I say, we don’t have sysadmin rights so we can’t just change the database properties using SSMS.
- Open the registry editor
- Navigate to…
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.10.SQLEXPRESS\MSSQLServer
One thing to note is I had a few different options under the “Microsoft SQL Server” branch so you may need to take an educated guess if yours is different.
Enable the sa user account and reset its password
I lumped these two into one section because the commands for them are entered at the same place.
- Open the Services applet in the Control Panel
- Find the “SQL Server (SQLEXPRESS)” entry and open its properties
- Stop the service
- Enter “-m” into the “Start parameters” field
- Start the service
- Open a Command Prompt
- Enter the command:
- At the next prompts enter the following commands:
- Stop the “SQL Server (SQLEXPRESS)” service
- Remove the “-m” from the Start parameters field
- Start the service
osql -S PC_NAME\SQLEXPRESS -E
Be sure to change PC_NAME to whatever your PC name is or you will get a big long message saying you messed up.
1> alter login sa enable 2> go 1> sp_password NULL,'new_password','sa' 2> go 1> quit
At this point you should be able to login to SSMS using the sa user account and the new password you gave it.
Leave a Reply
You must be logged in to post a comment.