title: Could not connect to SQL Server but Excel and ODBC config can
body: <p>I have a C# program to connect to SQL Server. It works fine at the test computer with SQL Server 2012 but does not work on the production environment with 2008. At the production environment, it reports exception as such,</p>
  
  <blockquote>
    <p>Unhandled Exception: System.Data.SqlClient.SqlException: A network-related or in
    stance-specific error occurred while establishing a connection to SQL Server. Th
    e server was not found or was not accessible. Verify that the instance name is c
    orrect and that SQL Server is configured to allow remote connections. (provider:
     Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) --
    -> System.ComponentModel.Win32Exception: Access is denied</p>
  </blockquote>
  
  <p>here is my connection code,</p>
  
  <pre><code>connStrSql = "Server=" + sqlserver + "; Database=" + sqldb + "; Trusted_Connection=True";
  SqlConnection sqlConn = new SqlConnection(connStrSql)
  sqlConn.Open();
  </code></pre>
  
  <p>The target platform is x86 and target framework is 4.5. The funny thing is that Excel and ODBC config can connect to the database without complain. Does C# program use different way connecting to SQL Server? How can I fix the problem?</p>