运行 .dtsx 文件通过命令行以编程方式从 winform c#
Running .dtsx file via command line programmatically from a winform c#
我是编程新手。我希望得到一些帮助来更正以下代码。
我有一个使用 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 数据库中。但是,我收到一条 return 消息,说明文件夹发生了变化。
任何有助于突出显示我出错的地方并纠正上述内容的帮助都会很棒。
请耐心等待,因为我是 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));
}
我用 "ImportScript.dtsx" 替换了 "FileName = "cmd.exe"。试试看。:) 我不是 100% 确定,但据我所知这是错误的。(也许其他人可以看到另一个问题,但至少尝试一下 :) )
您缺少参数的结尾 "
,尝试:
p.StartInfo.Arguments = @"/C dtexec/f ""C:\InboundWindow\ImportScript.dtsx""";
See here 用于使用双引号和 @
我是编程新手。我希望得到一些帮助来更正以下代码。
我有一个使用 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 数据库中。但是,我收到一条 return 消息,说明文件夹发生了变化。
任何有助于突出显示我出错的地方并纠正上述内容的帮助都会很棒。 请耐心等待,因为我是 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));
}
我用 "ImportScript.dtsx" 替换了 "FileName = "cmd.exe"。试试看。:) 我不是 100% 确定,但据我所知这是错误的。(也许其他人可以看到另一个问题,但至少尝试一下 :) )
您缺少参数的结尾 "
,尝试:
p.StartInfo.Arguments = @"/C dtexec/f ""C:\InboundWindow\ImportScript.dtsx""";
See here 用于使用双引号和 @