title: SQL Server 2008 Express connection string raises instance failure exception
body: <p>I'm using the following code to open a DB connection to an SQL Server 2008 Express instance and run queries from a DB script</p>
  
  <pre><code>private void ExecuteSql(String serverName, String sql)
  {
      String connectionString = String.Format("Server={0};Initial Catalog=master;Integrated Security=True;MultipleActiveResultSets=True;User Instance=False;Context Connection=False;Connect Timeout=300;", serverName.Trim());
      MessageBox.Show(connectionString);
  
      SqlConnection sqlConnection = new SqlConnection(connectionString);
      SqlCommand command = new SqlCommand();
      command.Connection = sqlConnection;
      sqlConnection.Open();
  
      try
      {
          var scripts = Regex.Split(sql, @"^\s*GO\s* ($ | \-\- .*$)", RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.IgnoreCase);
  
          foreach (var splitScript in scripts.Where(x =&gt; !String.IsNullOrWhiteSpace(x)).Select(x =&gt; x.Trim(' ', '\r', '\n')))
          {
              MessageBox.Show(splitScript);
              command.CommandText = splitScript;
              command.ExecuteNonQuery();
          }
      }
      finally
      {
          sqlConnection.Close();
      }
  }
  </code></pre>
  
  <p>When I run the code I always get an exception message "Instance failure"</p>
  
  <p>If I replace the line </p>
  
  <pre><code>String connectionString = String.Format("Server={0};Initial Catalog=master;Integrated Security=True;MultipleActiveResultSets=True;User Instance=False;Context Connection=False;Connect Timeout=300;", serverName.Trim());
  </code></pre>
  
  <p>by the same line but hard-coding the server name parameter</p>
  
  <pre><code>String connectionString = "Server=MACHINE-NAME\SQLEXPRESS;Initial Catalog=master;Integrated Security=True;MultipleActiveResultSets=True;User Instance=False;Context Connection=False;Connect Timeout=300;";
  </code></pre>
  
  <p>everything works fine.</p>
  
  <p>I've tried many different ways to create the connection string (<code>String.format</code>, <code>SqlConnectionStringBuilder</code>, string concatenation... ) but so far all of them raise the same problem when using the <code>serverName</code> parameter instead of hard-coding it </p>