title: Cannot connect to database using localhost\sqlserver
body: <p>I know we should be aware of such phrases but all of a sudden all my connections to <code>localhost\sqlexpress</code> stopped working.  As <code>.\sqlexpress</code> and <code>(local)\sqlexpress</code> 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...).</p>
  
  <p>But here are the details. As already mentioned I couldn't connect to <code>localhost\sqlexpress</code> but to <code>.\sqlexpress</code>. The same symptoms using SQL Server Manager, and connection strings for deployment and running wcf services. Funnily enough resolving the default instance as <code>localhost</code> works.</p>
  
  <p>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 <code>localhost</code> can be resolved using shared memory when using the native SQL client so I guess that is what's happening on his system.)</p>
  
  <p>The setup is only one SQL Server Express 2008 R2 instance and VS2010 on Windows 7 Professional.</p>
  
  <p><strong>Starting up Sql express the errorlog says:</strong></p>
  
  <pre><code>Server is listening on [ 'any' &lt;ipv6&gt; 1433].
  Server is listening on [ 'any' &lt;ipv4&gt; 1433].
  </code></pre>
  
  <p><strong>Netstat says (excerpt):</strong></p>
  
  <pre><code>TCP    0.0.0.0:1433           Machinenename:0             LISTENING
  TCP    [::]:1433              Machinenename:0             LISTENING
  </code></pre>
  
  <p>I note the absence of 127.0.0.1:1433 and any UDP on port 1433</p>
  
  <p>In order to diagnose the problem I use sqlcmd to find out what transport is used:</p>
  
  <p><strong>1. localhost\sqlexpress</strong></p>
  
  <pre><code>sqlcmd -Slocalhost\sqlexpress  -&gt; Shared memory
  sqlcmd -Stcp:localhost\sqlexpress -&gt;  SQL Server Network Interfaces: Error Locating Server/Instance Specified
  </code></pre>
  
  <p>Cannot connect to localhost\sqlexpress from SQL Server Management Studio even if I specify shared memory as protocol</p>
  
  <p><strong>2. localhost</strong></p>
  
  <pre><code>sqlcmd -Slocalhost -&gt; TCP
  sqlcmd -Stcp:localhost -&gt; TCP
  </code></pre>
  
  <p>Can connect to localhost from SQL Server Management Studio</p>
  
  <p><strong>3. (local)\sqlexpress</strong></p>
  
  <pre><code>sqlcmd -S(local)\sqlexpress  -&gt; Shared memory
  sqlcmd -Stcp:(local)\sqlexpress  -&gt;  SQL Server Network Interfaces: Error Locating Server/Instance Specified
  </code></pre>
  
  <p>Can connect to (local)\sqlexpress from SQL Server Management Studio</p>
  
  <p>So I am lost here. Any help is highly appreciated.</p>