title: Connection String for Remote Connections to SQL Server 2008
body: <p>I am trying to connect remotely to SQL Server 2008 R2 Express on a server running Windows Server 2008 R2. I receive the following error:</p>
  
  <blockquote>
    <p>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: TCP
    Provider, error: 0 - A connection attempt failed because the connected
    party did not properly respond after a period of time, or established
    connection failed because connected host has failed to respond.)</p>
  </blockquote>
  
  <p>I think the problem might be related to my connection string, because I am not sure exactly what it should be. I understand the connection string should take the form:</p>
  
  <pre><code>Data Source=123.123.123.123\InstanceName;Initial Catalog=MyDBName;user id=MyUserName;password=MyPassword;
  </code></pre>
  
  <p>The instance name of my SQL Server installation takes the form <code>ComputerName\SQLEXPRESS</code>. This is what I see when I log in to Management Studio on the server. So should the connection string begin with </p>
  
  <pre><code>Data Source=123.123.123.123\ComputerName\SQLEXPRESS
  </code></pre>
  
  <p>This looks wrong because of all the slashes. I have tried to omit the computer name thus:</p>
  
  <pre><code>Data Source=123.123.123.123\SQLEXPRESS
  </code></pre>
  
  <p>I also read somewhere that you can specify a port so I have also tried</p>
  
  <pre><code>Data Source=123.123.123.123,1433\SQLEXPRESS
  </code></pre>
  
  <p>because I understand that 1433 is the TCP port used by SQL Server and</p>
  
  <pre><code>Data Source=123.123.123.123,1434\SQLEXPRESS 
  </code></pre>
  
  <p>because I understand that 1434 is the UDP port used by SQL Server browser.</p>
  
  <p>I have also tried every combination of these and they all give the same error.</p>
  
  <p>These are the steps I have taken to enable remote browsing on the server:</p>
  
  <ol>
  <li><p>In Management Studio, right click the instance, go to Properties, Security and check SQL Server and Windows Authentication Mode. On the connections tab I have checked "Allow remote connections to this computer".</p></li>
  <li><p>In SQL Server Configuration Manager I have enabled all four connection options (Shared Memory, Named Pipes, TCPIP and Via) under every node they occur. Under protocols for SQL Express I have tried specifying port 1433 and also leaving it blank with TCP Dynamic Ports set to 0 (which I think is meant to enable dynamic ports).</p></li>
  <li><p>I have created firewall exceptions for TCP Port 1433, UDP Port 1434, and program exceptions for <code>sqlservr.exe</code> and <code>sqlbrowser.exe</code>.</p></li>
  </ol>
  
  <p>If someone could tell me which of the four versions of the DataSource part of the connection string I should be using it would be a great help, even if it did not solve the problem. It would mean that everything I try subsequently I would only have to test once instead of four times.</p>
  
  <p>Thanks in advance for any help!</p>