我确定这个问题已经得到解答,但我无法使用搜索工具找到答案.
使用c#我想运行一个.sql文件.sql文件包含多个sql语句,其中一些语句分为多行.我尝试在文件中读取并尝试使用ODP.NET执行文件...但是我不认为ExecuteNonQuery真的是为了这样做而设计的.
所以我尝试通过生成一个进程来使用sqlplus ...但是除非我将UseShellExecute设置为true而生成进程,否则sqlplus会挂起并永远不会退出.这是不起作用的代码.
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();
Run Code Online (Sandbox Code Playgroud)
WaitForExit永远不会返回....除非我将UseShellExecute设置为true.UseShellExecute的副作用是您无法捕获重定向的输出.