I got a laptop on which SQL Server Express is already installed. The server name is SRH\SQLEXPRESS and the version is 10.0.2531.0. The operating system is Windows 7.
I can connect to it through Windows Authentication. But I would like to connect to it though sa. Since I dont know the password of sa so I want to reset it. I decided to change it using osql.
These are the steps I took to change the password of sa:
- I opened command prompt (cmd) in Administrator mode.
- I typed in
osql -S SRH\SQLEXPRESS -Eand press Enter key. - Then I get the 1> prompt. I then typed in
sp_password null, 'HseWork11', 'sa'and press Enter key. - Then I get the 2> prompt. I then typed in
GOand press Enter key, But I get this error message:
Msg 15151, Level 16, State 1, Server SRH\SQLEXPRESS, Line 1 Cannot alter the login 'sa', because it does not exist or you do not have permission.
Bummer.
To confirm that the login sa exist, I connect through Windows Authentication and run this statement select * from sys.syslogins where name = 'sa'. I got 1 row back so the login sa exist.
So why I cannot change sa password using osql? what I am doing wrong?
Instead of using
sp_password, have you tried usingALTER LOGIN, perhaps with theUNLOCKoption? I usesqlcmdinstead ofosql- I don't actually know if that makes a difference.In the command prompt:
These are obviously different commands, and I know that sometimes
ALTER LOGINhas worked for me wheresp_passwordhas not. I don't believe it's a cure-all, but it might be worth taking a look.Side Note:
If this doesn't work, but you can still connect to SQL Server (you said you can, just not as SA), it might be worthwhile to run this query to see who can access SQL Server as an administrator. Maybe you have a built-in account that was given that role...
This will give you both SQL Server and Windows users who have the SysAdmin role.
First Edit:
You said that
is_disabledis marked as1for theSAaccount after running this query.Go back to your command prompt and try the following: