'Running .dtsx file via command line programmatically from a winform c#
I am new to programming. I was hoping for some help to correct the below code.
I have a WinForms application using an Azure SQL database. overall I am trying to automatically import a CSV file as it arrives in a cdrive location.
I have researched and tried BCP but failed to get passed Azure's security on my own account...., I don’t think my syntax is correctly built. I have also looked into Blob storage option again without much luck. I need to do more research on these options.
if I apply the following directly to the command line
dtexec/f “C:\InboundWindow\ImportScript.dtsx
I get a successful result outputted. With this, in mind, I have then dragged a fileSystemWatcher to my WinForms and then applied the following code.
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));
}
this is where it now fails I have tried many variations found on various forums however the .dtsx file is never imported to Azure SQL database. however, I get a return message stating a change in the folder.
Any help in highlighting where I am going wrong and correcting the above would be great. please bear with me as I am new to c# and programming in general. thanks
Solution 1:[1]
You're missing a closing "
for the Arguments, try:
p.StartInfo.Arguments = @"/C dtexec/f ""C:\InboundWindow\ImportScript.dtsx""";
See here for using double quotes and @
Solution 2:[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));
}
I replaced the "FileName = "cmd.exe" with "ImportScript.dtsx". Try that. :) I'm not 100 percent sure, but from what I can see that's the wrong. (Maybe other can see another problem, but at least try it :) )
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Zer0 |
Solution 2 | Putte |