Forgot SQL Server Password

后端 未结 6 930
无人及你
无人及你 2020-12-05 05:19

I installed SQL Server 2005 sometime ago and forgot the administrator password I set during setup. How can I connect to SQL server now?

EDIT: I thin

相关标签:
6条回答
  • 2020-12-05 05:51

    Thanks a lot cowgod

    It works Fine. I have Logged in to SQL Server with windows authentication mode. Then opened a new query window. There I typed these two commands by prssing F5.

    First run exec sp_password @new='changeme', @loginame='sa'

    Then alter login sa enable

    0 讨论(0)
  • 2020-12-05 05:52

    For these steps to work, you need to be an admin on box where SQL Server is installed.

    • Stop SQL Server from configuration manager
    • Start SQL Server in single user mode
    • Add this -mSQLCMD command as one of the start up parameters, by right clicking the service and going into startup parameters section as shown in screenshot below and start SQL Server

    • Now connect to SQLSERVER from SQLCMD (open command prompt as admin) like below:

      sqlcmd -s servername\instancename
      

      And run below command:

      USE [master]
      GO
      CREATE LOGIN [BUILTIN\Administrators] FROM WINDOWS WITH DEFAULT_DATABASE=[master]
      GO
      EXEC master..sp_addsrvrolemember @loginame = N'BUILTIN\Administrators', @rolename = N'sysadmin'
      GO
      

      Above command adds all local users as sysadmins. You may change this and add a user like or you can make another user sysadmin and remove BUILTIN\Administrators

    • Once this is done, you need to now stop SQL Server and remove -mSQLCMD parameter and restart SQL Server

    References:
    Help : I lost sa password and no one has System Administrator (SysAdmin) permission. What should I do?

    0 讨论(0)
  • 2020-12-05 06:01

    You don't need to pay for any reset tools to do this. Start the instance in single user mode and you can create a new login with sysadmin permissions/

    See this Pinal Dave link.

    0 讨论(0)
  • 2020-12-05 06:02

    If there's no other user with sysadmin privileges but sa, SQL Server should be restarted with -m option for single-user mode. Then you can connect to this SQL Server instance and you're able to add other users with sysadmin role or to execute exec sp_password.

    Pinal Dave explains here - http://blog.sqlauthority.com/2009/02/10/sql-server-start-sql-server-instance-in-single-user-mode/ - how to add -m with SQL Server Configuration Manager: right-click server service, go to Advanced tab and add -m; (notice semicolon) in Startup Parameters.

    Another way is to stop SQL Server instance in Services and to run it manually from the command line like this:

    "C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\Binn\sqlservr.exe" -m -sSQLEXPRESS

    I had to do that for SQL Server 2008 as it didn't appear in SQL Server 2008 R2 Configuration Manager. Exect command line can be found with in service properties.

    0 讨论(0)
  • 2020-12-05 06:03

    Try running the following commands at the command prompt (assuming your Server name is SQLEXPRESS):

    osql -E -S .\SQLEXPRESS
    exec sp_password @new='changeme', @loginame='sa'
    go
    alter login sa enable
    go
    exit
    

    Once you have completed these steps, try to login with username sa and password changeme.

    0 讨论(0)
  • 2020-12-05 06:07

    Unless you set it up to only accept SQL Server authentication, you can log on with integrated security using the administrator user of the domain and/or machine.

    0 讨论(0)
提交回复
热议问题