相关疑难解决方法(0)

如何使用c#执行.SQL脚本文件

我确定这个问题已经得到解答,但我无法使用搜索工具找到答案.

使用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的副作用是您无法捕获重定向的输出.

c# sql oracle scripting

128
推荐指数
6
解决办法
25万
查看次数

标签 统计

c# ×1

oracle ×1

scripting ×1

sql ×1