我确信这个问题已经得到了回答,但是我无法使用搜索工具找到答案。
使用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();
WaitForExit永远不会回来..。除非我将UseShellExecute设置为true。UseShellExecute的一个副作用是您无法捕获重定向的输出。
https://stackoverflow.com/questions/650098
复制相似问题