I know we should be aware of such phrases but all of a sudden all my connections to localhost\sqlexpress
stopped working. As .\sqlexpress
and (local)\sqlexpress
work, this wouldn't be a big deal if it weren't for the fact that I am working on a team project where all the connection strings are defined in the former format. And obviously I have a hard time to accept it shouldn't work anymore so I spent several hours analysing and reinstalling several SQL Server versions to no avail. (And on the way breaking the db projects in VS2010 so I needed to reinstall as well...).
But here are the details. As already mentioned I couldn't connect to localhost\sqlexpress
but to .\sqlexpress
. The same symptoms using SQL Server Manager, and connection strings for deployment and running wcf services. Funnily enough resolving the default instance as localhost
works.
First things first, yes the SQL Server is running and just to be sure I enabled TCP/IP and set the port fixed to 1433 although it works on my colleagues machine with TCP/IP disabled. (Somewhere along the way I read that localhost
can be resolved using shared memory when using the native SQL client so I guess that is what's happening on his system.)
The setup is only one SQL Server Express 2008 R2 instance and VS2010 on Windows 7 Professional.
Starting up Sql express the errorlog says:
Server is listening on [ 'any' <ipv6> 1433].
Server is listening on [ 'any' <ipv4> 1433].
Netstat says (excerpt):
TCP 0.0.0.0:1433 Machinenename:0 LISTENING
TCP [::]:1433 Machinenename:0 LISTENING
I note the absence of 127.0.0.1:1433 and any UDP on port 1433
In order to diagnose the problem I use sqlcmd to find out what transport is used:
1. localhost\sqlexpress
sqlcmd -Slocalhost\sqlexpress -> Shared memory
sqlcmd -Stcp:localhost\sqlexpress -> SQL Server Network Interfaces: Error Locating Server/Instance Specified
Cannot connect to localhost\sqlexpress from SQL Server Management Studio even if I specify shared memory as protocol
2. localhost
sqlcmd -Slocalhost -> TCP
sqlcmd -Stcp:localhost -> TCP
Can connect to localhost from SQL Server Management Studio
3. (local)\sqlexpress
sqlcmd -S(local)\sqlexpress -> Shared memory
sqlcmd -Stcp:(local)\sqlexpress -> SQL Server Network Interfaces: Error Locating Server/Instance Specified
Can connect to (local)\sqlexpress from SQL Server Management Studio
So I am lost here. Any help is highly appreciated.
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.
Connect to the SQL Server using SSMS Next, from the Connect menu under the Object Explorer, choose the Database Engine… Then, enter the information for the Server name (localhost), Authentication (SQL Server Authentication), and password for the sa user and click the Connect button to connect to the SQL Server.
Resolving The Problem. When you create the ODBC connection to SQL server, select the option of With SQL Server authentication using a login ID and password entered by the user. Also, confirm that in Microsoft Access, the Machine Data Source and System Data Source has been used to create the ODBC connection.
in MS SQL, go to Configuration tools -> SQL Server Configuration Manager Select SQL Server Network Configuration -> Select protocol in the right side window enable tcp/ip and restart the services in services.msc then try to connect to localhost\sqlexpress
Have you verified that Shared Memory is enabled in SQL Server Configuration Manager, under SQL Server Network Configuration | Protocols?
When I disable the "Shared Memory" protocol, "sqlcmd -S.\sqlexpress" times out. Enabling it makes the command work just fine.
One more thought... Port 1434 is used for the SQL Server Discovery service, which lets programs like SQL Management Studio and the like discover that SQL Server is running on the machine. Just one more thing to investigate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With