Can't connect to localhost on SQL Server Express 2012 / 2016
Asked Answered
P

14

120

I just downloaded the latest version of SQL Express 2012 but I cannot connect to localhost. I tried localhost\SQLExpress and Windows authentication but it gives me an error message saying cannot connect. Am I missing something here? I've used SQL Server 2008 before and I've never had issues connecting to localhost. It seems that it can't even find it. Also in the Services I only see a SQL Server VSS Writer. Is this the way it should be? Or am I missing something? Thanks

Philander answered 8/10, 2012 at 3:7 Comment(2)
Seems the installation didn't go well. Did you try repairing/re-installing it?Kirwin
Are you sure you found the installer for the server, as opposed to, say, a Management Studio installer?Chunky
P
220

According to Aaron Bertand:

  1. You need to verify that the SQL Server service is running. You can do this by going to Start > Control Panel > Administrative Tools > Services, and checking that the service SQL Server (SQLEXPRESS) is running. If not, start it.

  2. While you're in the services applet, also make sure that the service SQL Browser is started. If not, start it.

  3. You need to make sure that SQL Server is allowed to use TCP/IP or named pipes. You can turn these on by opening the SQL Server Configuration Manager in Start > Programs > Microsoft SQL Server 2012 > Configuration Tools (or SQL Server Configuration Manager), and make sure that TCP/IP and Named Pipes are enabled. If you don't find the SQL Server Configuration Manager in the Start Menu you can launch the MMC snap-in manually. Check SQL Server Configuration Manager for the path to the snap-in according to your version.

    SQL Server Configuration Manager

  4. Verify your SQL Server connection authentication mode matches your connection string:

    • If you're connecting using a username and password, you need to configure SQL Server to accept "SQL Server Authentication Mode":

      -- YOU MUST RESTART YOUR SQL SERVER AFTER RUNNING THIS!
      USE [master]
      GO
      DECLARE @SqlServerAndWindowsAuthenticationMode INT = 2;
      EXEC xp_instance_regwrite
        N'HKEY_LOCAL_MACHINE',
        N'Software\Microsoft\MSSQLServer\MSSQLServer',
        N'LoginMode',
        REG_DWORD,
        @SqlServerAndWindowsAuthenticationMode;
      GO
      
    • If you're connecting using "Integrated Security=true" (Windows Mode), and this error only comes up when debugging in web applications, then you need to add the ApplicationPoolIdentity as a SQL Server login:
  5. otherwise, run Start -> Run -> Services.msc If so, is it running?

If it's not running then

It sounds like you didn't get everything installed. Launch the install file and chose the option "New installation or add features to an existing installation". From there you should be able to make sure the database engine service gets installed.

Pyromancy answered 8/10, 2012 at 3:13 Comment(10)
@dido:Start->Run->Services.mscPyromancy
Another thing to check is the instance name. Depending on how SQL Server was installed you may or may not need to provide an instance name after the host.Nunley
"TCP/IP and Named Pipes are enabled" seems to be necessary after first installingCelom
I can see an angle wing behind you! Saving the day.Morphophonemics
It was stupid but for me, the problem was using "localhost" as the server name and not "localhost\SQLEXPRESS01" as was set in the installationFraktur
Note that if you're using the default instance name like MSSQLSERVER or SQLEXPRESS then you might be able to connect with just "LocalHost". In fact, using the full name like LocalHost\MSSQLSERVER might not work (did not for me). Yet, for a custom instance name like SQLEXPRESS01 you must include the name. And up vote Ravindra for helpful info.Receptacle
In my case SQLBrowser was disabled and the configuration tool wasnt listed in the sql tools folder. To start the config tool via cmd https://learn.microsoft.com/en-us/sql/relational-databases/sql-server-configuration-manager?view=sql-server-2017 To start the SQLBrowser automatically if the config tool fails https://mcmap.net/q/75922/-i-cannot-start-sql-server-browserTshirt
Adding the User and setting their permissions to db_owner fixed my issue.Imaret
"Windows could not start the SQL Server (MSSQLSERVER) on Local Computer"Chutney
In 2022 this is STILL the solution to connect to SQL Server Express locally using a non-Management Studio tool!Robertroberta
D
162

Goto Start -> Programs -> Microsoft SQL ServerYYYY -> Configuration Tools -> SQL Server YYYY Configuration Manager or run "SQLServerManager12.msc".

Make sure that TCP/IP is enabled under Client Protocols.

Then go into "SQL Server Network Configuration" and double click TCP/IP. Click the "IP Addresses" tab and scroll to the bottom. Under "IP All" remove TCP Dynamic Ports if it is present and set TCP Port to 1433. Click OK and then go back to "SQL Server Services" and restart SQL Server instance. Now you can connect via localhost, at least I could.

enter image description here

Note that this error can of course occur when connecting from other applications as well. Example for a normal C# web application Web.config connection string:

<connectionStrings>
    <add name="DefaultConnection" connectionString="server=localhost;database=myDb;uid=myUser;password=myPass;" />
</connectionStrings>
Dyeline answered 28/12, 2015 at 13:7 Comment(0)
O
25

in SQL SERVER EXPRESS 2012 you should use "(localdb)\MSSQLLocalDB" as Data Source name for example you can use connection string like this

Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=master;Integrated Security=True;
Opsonize answered 5/4, 2017 at 11:27 Comment(3)
Great! Using (localdb)\MSSQLLocalDB worked to connect to SSMS when localhost didn't workUndesigning
Work for me alsoHerwick
It is also default local db connection for SQL Server Express 2019Abruzzi
K
21

First try the most popular solution provided by Ravindra Bagale.

If your connection from localhost to the database still fails with error similar to the following:

Can't connect to SQL Server DB. Error: The TCP/IP connection to the host [IP address], port 1433 has failed. Error: "Connection refused: connect. Verify the connection properties. Make sure that an instance of SQL Server is running on the host and accepting TCP/IP connections at the port. Make sure that TCP connections to the port are not blocked by a firewall."

  1. Open the SQL Server Configuration Manager.
  2. Expand SQL Server Network Configuration for the server instance in question.
  3. Double-click "TCP/IP".
  4. Under the "Protocol" section, set "Enabled" to "Yes".
  5. Under the "IP Addresses" section, set the TCP port under "IP All" (which is 1433 by default).
  6. Under the "IP Addresses" section, find subsections with IP address 127.0.0.1 (for IPv4) and ::1 (for IPv6) and set both "Enabled" and "Active" to "Yes", and TCP port to 1433.

    TCP/IP Properties

  7. Go to Start > Control Panel > Administrative Tools > Services, and restart the SQL Server service (SQLEXPRESS).

Kalsomine answered 25/1, 2018 at 11:7 Comment(2)
I tried the other solutions above before getting here. This one fixed it for me! Also, I found downloading a thing called psping helped me test the connection. Example: psping 127.0.0.1:1433Saltsman
it did not work for me until I set IP Address 127.0.0.1 and port 1433 on IP4Honora
W
11

I had a similar problem - maybe my solution will help. I just installed MSSQL EX 2012 (default install) and tried to connect with VS2012 EX. No joy. I then looked at the services, confirmed that SQL Server (SQLEXPRESS) was, indeed running.

However, I saw another interesting service called SQL Server Browser that was disabled. I enabled it, fired it and was then able to retrieve the server name in a new connection in VS2012 EX and connect.

Odd that they would disable a service required for VS to connect.

Wagram answered 3/3, 2013 at 21:35 Comment(1)
It isn't required to connect; I have it disabled and I can connect fine. It just makes things easier when you don't know the precise host/instance name to connect to as it allows those things to be queried by other software.Prickly
V
10

First check SQL Server Service is Running or stopped, if it is stopped just start it, to do so..just follow the below steps.

1.Start -> Run ->Services.msc

enter image description here

  1. Go to Standard tab in services panel then search for SQl Server(SQL2014)

"SQL2014" is given By me, it may be Another Name in your case

enter image description here

that's it once you start the SQL Service, you are able to connect local database.

hope it will help someone.

Vesture answered 28/10, 2016 at 6:13 Comment(0)
S
8

All my services were running as expected, and I still couldn't connect.

I had to update the TCP/IP properties section in the SQL Server Configuration Manager for my SQL Server Express protocols, and set the IPALL port to 1433 in order to connect to the server as expected.

enter image description here

Soule answered 24/10, 2018 at 15:19 Comment(0)
B
8

After doing the steps which were mentioned by @Ravindra Bagale, Try this step. Server name: localhost\{Instance name you were gave}

enter image description here

Bynum answered 3/6, 2019 at 4:2 Comment(0)
C
3

Try changing from windows authentication to mixed mode

Cattima answered 16/1, 2015 at 12:32 Comment(0)
U
2

The problem for me was that I was not specifying .\. I was only specifying the name of the instance:

  • did not work: SQL2016
  • worked: .\SQL2016
Unmake answered 13/11, 2018 at 16:54 Comment(0)
H
1

This is odd I have a similar problem. I downloaded the package for SQL 2012 Express with Tools but the Database Engine was not install.

I donloaded the other one from the MS site and this one installed the database engine. After a reboot the services were listed and ready to go.

Hereinafter answered 30/9, 2013 at 19:52 Comment(0)
P
1

My situation

  • empty Instance Name in SQL Server Management Studio > select your database engine > Right Mouse Button > Properties (Server Properties) > Link View connection properties > Product > Instance Name is empty

  • Data Source=.\SQLEXPRESS did not work => use localhost in web.config (see below)

Solution: in web.config

xxxxxx = name of my database without .mdf yyyyyy = name of my database in VS2012 database explorer

You can force the use of TCP instead of shared memory, either by prefixing tcp: to the server name in the connection string, or by using localhost.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring%28v=vs.110%29.aspx

Prerecord answered 24/4, 2014 at 13:0 Comment(0)
H
1

I had the same issue and I found that this happened after I installed an update for my SQL 2012. What fixed it for me was going into programs and features and running a repair on it.

Holograph answered 19/9, 2014 at 15:23 Comment(0)
W
0

Try changing the User that owns the service to Local System or use your admin account.

Under services, I changed the Service SQL Server (MSSQLSERVER) Log On from NT Service\Sql... To Local System. Right click the service and go to the Log On Tab and select the radio button Local System Account. You could also force another User to run it too if that fits better.

Woundwort answered 10/12, 2018 at 21:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.