通过命令行从winform c#以编程方式运行.dtsx文件

问题描述 投票:2回答:2

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

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

我已经研究并尝试过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#和编程。谢谢

c# winforms command-line ssis filesystemwatcher
2个回答
3
投票

你错过了关于参数的结束",试试:

p.StartInfo.Arguments = @"/C dtexec/f ""C:\InboundWindow\ImportScript.dtsx""";

See here使用双引号和@


1
投票
 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));


    }

我用“ImportScript.dtsx”替换了“FileName =”cmd.exe“。试试吧。:)我不是百分百肯定,但从我看到的是错误的。(也许其他人可以看到另一个问题,但是至少试试:))

© www.soinside.com 2019 - 2024. All rights reserved.