【问题标题】:Running .dtsx file via command line programmatically from a winform c#从 winform c# 以编程方式通过命令行运行 .dtsx 文件
【发布时间】:2019-02-20 14:27:55
【问题描述】:

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

我有一个使用 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));


}

现在失败了但是,我收到一条返回消息,说明文件夹发生了变化。

任何帮助突出我哪里出错并纠正上述内容都会很棒。 请多多包涵,因为我是 c# 和一般编程的新手。谢谢

【问题讨论】:

  • 您缺少Arguments 的结束":尝试p.StartInfo.Arguments = @"/C dtexec/f ""C:\InboundWindow\ImportScript.dtsx"""; 请参阅here 使用双引号和@
  • 谢谢!!我正在调查这个。干杯
  • Zer0 - 您的编辑成功了!!真的非常感谢你。亲切的问候迈克尔
  • 我把它放在一个答案中。请将其标记为已接受,以便问题结束。谢谢。

标签: c# winforms command-line ssis filesystemwatcher


【解决方案1】:

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

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

See here 用于使用双引号和@

【讨论】:

  • 您的编辑成功了!!真的非常感谢你。亲切的问候迈克尔
【解决方案2】:
 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”。试试这个。:) 我不是 100% 确定,但据我所知,这是错误的。(也许其他人可以看到另一个问题,但至少尝试一下 :) )

【讨论】:

  • 感谢您的快速回复。我已经运行了上述内容,现在在 p.Start() 上出现错误; System.ComponentModel.Win32Exception: '系统找不到指定的文件。我目前正在审查原因。再次欢呼
  • 我不太确定“.dtsx”文件是什么,但 Windows 是否支持它?所以你可以运行文件格式,当我构建一个 C# 应用程序时,我得到了同样的错误,后来显示我无法从这个操作系统(即 windows)运行 .jar 文件所以。我不太确定您的 .dtsx 文件,但我想您应该等待另一个答案才能弄清楚。
猜你喜欢
  • 2012-04-25
  • 2021-10-28
  • 1970-01-01
  • 2019-04-16
  • 2012-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多