Unable to connect SQL Server

Issue:

After installed the 1st SQL Server with Windows Authentication only, due to the following reasons, you are locked out of access to the SQL Server.

  • All logins that are members of the sysadmin fixed server role have been removed by mistake.
  • All Windows Groups that are members of the sysadmin fixed server role have been removed by mistake.
  • The logins that are members of the sysadmin fixed server role are for individuals who have left the company or who are not available.
  • The sa account is disabled or no one knows the password.

One way in which you can regain access is to reinstall SQL Server and attach all the database to the new instance. This solution is time-consuming; and to recovery the logins, it might require restoring the master database from a backup.

Resolution:

Start the instance of SQL Server in single-user mode by using either the -m or -f options. Any member of the computer’s local Administrators group can then connect to the instance of SQL Server as a member of the sysadmin fixed server role.

Note

When you start an instance of SQL Server in single-user mode, first stop the SQL Server Agent service. Otherwise, SQL Server Agent might connect first and prevent you from connecting as a second user.

When you use the -m option with sqlcmd or SQL Server Management Studio, you can limit the connections to a specified client application. For example, -m”sqlcmd” limits connections to a single connection and that connection must identify itself as the sqlcmd client program. Use this option when you are starting SQL Server in single-user mode and an unknown client application is taking the only available connection. To connect through the Query Editor in Management Studio, use -m”Microsoft SQL Server Management Studio – Query”.

Steps to resolve:

  1. Go to “Start”à“All programs”à“Microsoft SQL Server 2008 R2″à“SQL Server Configuration Manager”
  2. Expand the Configuration Manager, locate “SQL Server Services”, in the right area, right-click “SQL Server(MSSQLServer)” and

    Select “Stop”.

    Then you will see the similar screen-shot below:

  3. Alt back to “Command Console”, then enter “C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLServer\MSSQL\Binn”

    Run the command below, it will start the sql server with single-user mode.

    After running the command above, you will see the result below:

  4. Open “SMSS” , in “Connect to SQL Server ” window, keep the default connection mode.

    Click “Connect”, you will find that you have connected it successfully.

    The exception here in GUI is that there is red icon in the instance, but it does not matter here.

  5. Trying to expand the Security” node, add the missing login or window login. Here I added the moss_setup_acct domain account.

    Then close the SMSS.

  6. Go back to single-user mode of “Command Console” (Step 3 above), Press “Ctrol + C” key to cancel the command console.

  7. Go back to “SQL Server Configuration Manager” to start the SQL Server again.

  8. Re-open “SMSS” like step 4.

    Just keep the default and click “Connect”

原文地址:https://www.cnblogs.com/bigholy/p/2172096.html