C# 从WinC窗体通过命令行以编程方式运行.dtsx文件#

C# 从WinC窗体通过命令行以编程方式运行.dtsx文件#,c#,winforms,command-line,ssis,filesystemwatcher,C#,Winforms,Command Line,Ssis,Filesystemwatcher,我是编程新手。我希望得到一些帮助来更正下面的代码 我有一个使用Azure SQL数据库的WinForms应用程序。总的来说,我试图在CSV文件到达cdrive位置时自动导入它 我已经研究并尝试了BCP,但在我自己的帐户上未能通过Azure的安全性…,我认为我的语法没有正确构建。我还再次研究了Blob存储选项,但运气不太好。我需要对这些选项做更多的研究 如果我将以下内容直接应用于命令行 dtexec/f “C:\InboundWindow\ImportScript.dtsx 我得到了一个成功的

我是编程新手。我希望得到一些帮助来更正下面的代码

我有一个使用Azure SQL数据库的WinForms应用程序。总的来说,我试图在CSV文件到达cdrive位置时自动导入它

我已经研究并尝试了BCP,但在我自己的帐户上未能通过Azure的安全性…,我认为我的语法没有正确构建。我还再次研究了Blob存储选项,但运气不太好。我需要对这些选项做更多的研究

如果我将以下内容直接应用于命令行

dtexec/f “C:\InboundWindow\ImportScript.dtsx 
我得到了一个成功的结果输出。考虑到这一点,我将一个fileSystemWatcher拖到我的WinForms中,然后应用以下代码

private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e) {


  // Process.Start("cmd", @"/C dtexec/f “C:\InboundWindow\ImportScript.dtsx");
  Process p = new Process();
  p.StartInfo.FileName = "cmd.exe";
  p.StartInfo.Arguments = @ "/C dtexec/f “C:\InboundWindow\ImportScript.dtsx";
  p.StartInfo.RedirectStandardOutput = false;
  p.StartInfo.UseShellExecute = false;
  p.StartInfo.CreateNoWindow = false; //don't show the console at all
  p.Start();


  // FullPath is the new file's path.
  MessageBox.Show(string.Format("Created: {0} {1}", e.FullPath, e.ChangeType));


}
这就是它现在失败的地方。我尝试了各种论坛上的许多变体,但是.dtsx文件从未导入Azure SQL数据库。但是,我收到一条返回消息,说明文件夹中发生了更改

任何有助于突出我的错误并纠正上述错误的方法都是非常好的。 请容忍我,因为我是c#和编程新手。谢谢

 private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
    {


       // Process.Start("cmd", @"/C dtexec/f “C:\InboundWindow\ImportScript.dtsx");
        Process p = new Process();
        p.StartInfo.FileName = "ImportScript.dtsx"; //Since this is the name of the file that's going to be started
        p.StartInfo.Arguments = @"/C dtexec/f “C:\InboundWindow\ImportScript.dtsx";
        p.StartInfo.RedirectStandardOutput = false;
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.CreateNoWindow = false;  //don't show the console at all
        p.Start();


        // FullPath is the new file's path.
        MessageBox.Show(string.Format("Created: {0} {1}", e.FullPath, e.ChangeType));


    }

我将“FileName=“cmd.exe”替换为“ImportScript.dtsx”。试试看。:)我不是100%确定,但从我看来这是错误的。(也许其他人可以看到另一个问题,但至少试试看:)

您缺少参数的结束符
,请尝试:

p.StartInfo.Arguments=@/C dtexec/f“C:\InboundWindow\ImportScript.dtsx”


对于使用双引号和
@

参数,您缺少一个结束符
:请尝试
p.StartInfo.Arguments=@”/C dtexec/f”“C:\InboundWindow\ImportScript.dtsx”";请参阅使用双引号和
@
。谢谢!!我正在调查此事。干杯0-你的编辑成功了!!非常感谢你。善意的问候迈克尔在回答中说。请将其标记为已接受,以便问题结束。谢谢,谢谢你的快速反应。我已经运行了上面的程序,现在在p.Start()上出现了一个错误;System.ComponentModel.Win32Exception:'系统找不到指定的文件。我现在正在回顾为什么。我不确定“.dtsx”文件是什么,但windows支持吗?所以你可以运行文件格式,有一次当我构建一个C#应用程序时,我遇到了同样的错误,后来我发现我无法从这个操作系统(即windows)运行.jar文件。我对你的.dtsx文件不是很确定,但我想你应该等待另一个答案才能把它弄清楚。你的编辑成功了!!非常感谢你。向迈克尔问好