title: How to run .sql script using C#, also need to pass values for parameters that are declared in .sql file?
body: <p>Lets say I have following in my MyScript.Sql file</p>
  
  <pre><code>declare @city char(10)
  
  set @city = 'Berlin'
  
  If EXISTS( SELECT * FROM Customer where city = @city)
  begin
   ---some stuff to do with the record---
  end
  </code></pre>
  
  <p>using following code, i'm able to run above .sql file.</p>
  
  <pre><code>string sqlConnectionString = @"MyCS";
  
      FileInfo file = new FileInfo(@"(location of .sql file");
  
      string script = file.OpenText().ReadToEnd();
  
      SqlConnection conn = new SqlConnection(sqlConnectionString);
  
      Server server = new Server(new ServerConnection(conn));
  
      server.ConnectionContext.ExecuteNonQuery(script);
      file.OpenText().Close();
  </code></pre>
  
  <p>Now, I want to be able to dynamically pass the value of @city from my C# code to the .sql script instead of setting it's value in .sql file itself. How can I do that? Thanks!</p>