我是编程的新手。我希望有一些帮助来纠正以下代码。
我使用Azure SQL数据库具有Winforms应用程序。总的来说,我正在尝试在CDRive位置到达CSV文件时自动导入CSV文件。
我已经研究并尝试了BCP,但未能通过我自己的帐户获得Azure的安全性。...,我认为我的语法不是正确构建的。我还没有多运气研究了Blob存储选项。我需要对这些选择进行更多研究。
如果我将以下内容直接应用于命令行
dtexec/f “C:InboundWindowImportScript.dtsx
我获得了成功的结果。考虑到这一点,我随后将FilesystemWatcher拖到了我的Winforms,然后应用了以下代码。
private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e) {
// Process.Start("cmd", @"/C dtexec/f “C:InboundWindowImportScript.dtsx");
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = @ "/C dtexec/f “C:InboundWindowImportScript.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#的新手和一般编程。谢谢
您错过了参数的闭合"
,请尝试:
p.StartInfo.Arguments = @"/C dtexec/f ""C:InboundWindowImportScript.dtsx""";
请参阅此处使用双引号和@
private void fileSystemWatcher1_Created(object sender, FileSystemEventArgs e)
{
// Process.Start("cmd", @"/C dtexec/f “C:InboundWindowImportScript.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:InboundWindowImportScript.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。问题,但至少尝试一下:))