Skip to content
Advertisement

How to execute an .SQL script file using c#

I’m sure this question has been answered already, however I was unable to find an answer using the search tool.

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.

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.

WaitForExit never returns …. Unless I set UseShellExecute to true. A side effect of UseShellExecute is that you can no capture the redirected output.

Advertisement

Answer

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement