SQL Server 2012 – How to Access a Fresh Installation

installationsql serversql-server-2012

I've performed a fresh install of SQL Server 2012 on my local development PC. I've done this before and it has worked, however this time I'm getting the following error message when I attempt to sign into SQL Server.

"Login failed for user xxxxxxxxxx (Microsoft SQL Server, Error: 18456)"

How can I access my local instance of SQL Server? I'm rather ignorant about SQL Server security.

Best Answer

Since you have access to the machine itself, you can follow the instructions here to (re)add yourself as a sysadmin: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/connect-to-sql-server-when-system-administrators-are-locked-out

The short version of what that says is:

  1. Stop SQL Server
  2. Restart with the minimal configuration option -m
  3. Log into the server with sqlcmd -S {your machine name or localhost}
  4. Run the following commands:
    1. CREATE LOGIN [Domain\LoginName] FROM WINDOWS;
    2. EXEC sp_addsrvrolemember '[Domain\LoginName]', 'sysadmin';
  5. Stop SQL Server
  6. Restart it with the normal configuration