title: Unable to connect to SQL database - C#, VS2012, SQL Server 2012
body: <p><strong>I have SQL Server 2005, 2008 and 2012 installed on my Windows 7 64bit PC.</strong></p>
  
  <p><img src="https://i.stack.imgur.com/GVdq4.png" alt="enter image description here"></p>
  
  <hr>
  
  <p><strong>Here is my Configuration Manager, and I do see that the Agent is Stopped... not sure if this is required.  I've split it out into two images so the size shows up larger</strong></p>
  
  <p><img src="https://i.stack.imgur.com/uXWEh.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/P5RuP.png" alt="enter image description here"></p>
  
  <hr>
  
  <p><strong>Here is what is shown in the VS2012 Database Explorer window.  This is a SQL Server 2012 database</strong></p>
  
  <p><img src="https://i.stack.imgur.com/fMCLR.png" alt="enter image description here"></p>
  
  <hr>
  
  <p><strong>Here is my code</strong></p>
  
  <pre><code>string selectSql = "select * from Tasks";
  
  string connectionString = "Data Source=adamssqlserver;Database=master;Integrated Security=True;";
  
  using (var cn = new SqlConnection(connectionString))
  using (var cmd = new SqlCommand(selectSql, cn))
  {
      cn.Open(); // this is the line that throws the error message.
      using (var reader = cmd.ExecuteReader())
      {
              //do something
      }
  }
  </code></pre>
  
  <p><strong>As noted, the cn.Open(); line is what throws the error message shown below</strong></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: Named
    Pipes Provider, error: 40 - Could not open a connection to SQL Server)</p>
  </blockquote>