Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot connect to MSSQL server management studio as localhost

I installed MSSQL server 2016 with configuration manager and management studio. I trying connect to SQL server via management studio:

  • Server type: Database Engine
  • Server name: localhost
  • Authentication: Windows Authentication

Error TITLE: Connect to Server:

Cannot connect to localhost. A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2) The system cannot find the file specified

Nothing more information in event viewer. I have these services with states:

  • SQL Server (SQLEXPRESS) - Running
  • SQL Full-text Filter Daemon Launcher (SQLEXPRESS) - Running
  • SQL Server Launchpad (SQLEXPRESS) - Running
  • SQL Server Reporting Services (SQLEXPRESS) - Running
  • SQL Server Agent (SQLEXPRESS) - Stopped
  • SQL Server Browser - Running

After try start SQL Server Agent i get this error:

The SQL Server Agent (SQLEXPRESS) service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.

Thank you for any advice.

EDIT

I capture a screen of sql services: enter image description here

like image 542
Frantisek Pastorek Avatar asked Aug 10 '18 13:08

Frantisek Pastorek


3 Answers

In an attempt to get all the answers in one spot (and hopefully help a future searcher), you can connect to the SQL box that SQL Management Studio is installed on by changing the Server name: in the connection dialog

enter image description here

to one of the following:

  • (localdb)\MSSQLLocalDB
  • .
  • 127.0.0.1 - by direct IP address, this is your loopback IP
  • The actual IP address of the machine
  • The name of the machine you are on, several ways to figure this out. https://www.cnet.com/how-to/find-out-your-computers-name-and-windows-edition-in-two-clicks/
  • The named instance of SQL you have locally installed, in this case: .\SQLEXPRESS
  • The machine name and the SQL instance like: YOURCOMPUTERNAME\SQLEXPRESS2017
  • LOCALHOST
like image 75
sniperd Avatar answered Nov 17 '22 04:11

sniperd


I could solve the same issue only with server name (localdb)\MSSQLLocalDB. Just FYI

like image 32
sandy Avatar answered Nov 17 '22 05:11

sandy


May be this is familiar to many, but I believe new starters may find this helpful! As similar like above snapshot provided in the problem, I did not find MSSQLSERVER service is showing in SQL Server Configuration Manager. The reason is that I just installed the exe, but failed to do sql server setup actually! To make my 'localhost' as server name with windows authentication works, I followed below steps.

  1. Open SQL Server 2019 Installation Centre. [Note: For SQL Server Installation Media Path, choose location C:\SQL2019\Express_ENU]. This will open installation Wizard.
  2. Go to Installation -> Choose 'New SQL Server stand-alone installation or add features to an existing installation'
  3. In Installation Type -> Choose 'Perform a new installation of SQL Server 2019'
  4. Follow the instructions and in between the setup, it will prompt to setup password for 'sa'. You can choose either windows mode or mixed mode ( i.e. windows and sql server authentication). [NOTE: This sa password setup will not be prompted during installation from exe.]
  5. Complete the setup.
  6. Once completed, you can see 'MSSQLSERVER' is running.
  7. Just type in 'localhost' with windows authentication by default.
  8. This time, just enter 'localhost' in server name like below enter image description here
  9. It will then connected immediately without any hassles. local host db connected
like image 2
Viswa Avatar answered Nov 17 '22 05:11

Viswa