【发布时间】:2010-10-13 14:25:08
【问题描述】:
我确定这个问题已经得到解答,但是我无法使用搜索工具找到答案。
使用 c# 我想运行一个 .sql 文件。 sql 文件包含多条 sql 语句,其中一些语句被分成多行。我尝试读取文件并尝试使用 ODP.NET 执行文件……但是我不认为 ExecuteNonQuery 真的是为此而设计的。
所以我尝试通过生成进程来使用 sqlplus ... 但是,除非我使用设置为 true 的 UseShellExecute 生成进程,否则 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 的一个副作用是您无法捕获重定向的输出。
【问题讨论】:
-
Rich 先生您好,您的问题是关于 Oracle 的,您接受了针对 sql server 的解决方案?您将数据库更改为 sql server 吗?