c# - SQL CLR 调用 Process.Start 挂起或失败
问题描述
我已经检查过,有很多类似的帖子,但我无法解决这个问题。这是一个 SQL CLR proc,用于运行解析 PDF 文件的 exe。我可以在控制台应用程序中运行与我自己相同的代码。权限不是问题。我正在转储到事件日志,并且 ProcessStartInfo 已完整形成。UseShellExecute - 我不确定。我还创建了一个 .bat 文件来执行代码 - 手动运行它 - 它运行良好。通过这个 CLR 程序?立即挂起或奔跑,但什么也不做。斗智斗勇。我的目标是使用 itext 中的 Nuget 创建 CLR,但我很难安装。SQL CLR 不支持它,但我还是尝试了。
提前致谢。
[Microsoft.SqlServer.Server.SqlProcedure]
public static void PDFToCSVViaExe_CLR()
{
ProcessStartInfo startInfo = new ProcessStartInfo();
string args = @"\\app\Systems\Universal";
args = " \"" + args + "\"" + " \"" + "*" + "\"" + " \"" + "LVM" + "\"";
startInfo.CreateNoWindow = false;
startInfo.UseShellExecute = true;
startInfo.FileName = "c:\\SqlCLR\\PDFRipper\\PDFToCSV.exe";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.Arguments = args;
EventLog.WriteEntry(".NET Runtime", startInfo.FileName.ToString()+" " + args, EventLogEntryType.Warning, 1000);
string folder = "C:\\SqlCLR\\PDFRipper\\LVM.bat";
try
{
//using (new ImpersonationNamespace.Impersonation("domain", "user", "password"))
{
EventLog.WriteEntry(".NET Runtime", System.Security.Principal.WindowsIdentity.GetCurrent().Name + " OR " + Environment.UserName, EventLogEntryType.Warning, 1000);
folder = System.IO.Path.GetDirectoryName(folder);
if (!Directory.Exists(folder))
{
throw (new Exception("Directory does not exist for " + folder));
}
else
{ EventLog.WriteEntry(".NET Runtime", folder + " exists.", EventLogEntryType.Warning, 1000); }
// Start the process with the info we specified.
// Call WaitForExit and then the using statement will close.
using (Process exeProcess = Process.Start(startInfo))
{
exeProcess.WaitForExit();
}
}
}
catch (Exception ex)
{
using (EventLog EventLog = new EventLog("Application"))
{
EventLog.Source = "Application";
//eventLog.WriteEntry(ex.Message);
EventLog.WriteEntry(".NET Runtime", ex.Message + "Trace" + ex.StackTrace, EventLogEntryType.Warning, 1000);
//eventLog.WriteEntry(".NET Runtime", ex.Message, EventLogEntryType.Warning, 1000);
}
}
解决方案
推荐阅读
- javascript - 如果将新值添加到 Angular 的输入中,如何刷新下拉列表?
- c# - 命中 API -RestSharp 时无法连接到远程服务器
- sql - 使用 out 参数调用 plsql 过程 = null
- vue.js - 在 Vue 前端使用 Pusher 和 Laravel Echo 实现 Laravel 8 广播
- blazor - Blazor WASM 项目中的哪些文件夹具有“意义”?
- swift - 有没有办法跟踪用户在 Swift Playgrounds 中输入的内容?
- heroku - Flask-Mail - 超时和错误?[Errno - 3] 发送邮件时
- mysql - “SELECT column1 FROM table1”和“SELECT ALL column1 FROM table1”之间的区别
- ios - 如何从 Objective C 的 intValue 中已超过 MaxValue(2147483647) 中获取原始 Long 值
- python - 使用 Python3.x Tensorflow2 加载数据后使用预训练的 MobileNet 时出错(尺寸错误)