title: How to execute an .SQL script file using c#
body: <p>I'm sure this question has been answered already, however I was unable to find an answer using the search tool.</p>
  
  <p>Using c# I'd like to run a .sql file. The sql file contains multiple sql statements, some of which are broken over multiple lines. I tried reading in the file and tried executing the file using ODP.NET ... however I don't think ExecuteNonQuery is really designed to do this.</p>
  
  <p>So I tried using sqlplus via spawning a process ... however unless I spawned the process with UseShellExecute set to true sqlplus would hang and never exit. Here's the code that DOESN'T WORK.</p>
  
  <pre><code>Process p = new Process();
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.RedirectStandardOutput = true;
  p.StartInfo.FileName = "sqlplus";
  p.StartInfo.Arguments = string.Format("xx/xx@{0} @{1}", in_database, s);
  p.StartInfo.CreateNoWindow = true;
  
  bool started = p.Start();
  p.WaitForExit();
  </code></pre>
  
  <p>WaitForExit never returns .... Unless I set UseShellExecute to true. A side effect of UseShellExecute is that you can no capture the redirected output.</p>