behi behi behi behi - 27 days ago 6
ASP.NET (C#) Question

Why i get error in dtexec command in asp.net?

I'm new in

asp.net
,and want to write code to run
sql server
dtexec
for that purpose write this code:


System.Diagnostics.Process si = new System.Diagnostics.Process();
si.StartInfo.WorkingDirectory = @"c:\";
si.StartInfo.UseShellExecute = false;
si.StartInfo.FileName = "cmd.exe";
si.StartInfo.Arguments = "/C dtexec / f E:/Package.dtsx / set /package.variables[FilePath].Value; e:\testFile.txt";

si.StartInfo.CreateNoWindow = true;
si.StartInfo.RedirectStandardInput = true;
si.StartInfo.RedirectStandardOutput = true;
si.StartInfo.RedirectStandardError = true;
si.Start();
string output = si.StandardOutput.ReadToEnd();
si.Close();




but when i run that code,get this error:


Microsoft (R) SQL Server Execute Package Utility Version 12.0.2000.8 for 64-bit Copyright (C) Microsoft Corporation. All rights reserved. Option "/" is not valid.




How can i solve that problem?thanks all.

Answer

You should remove whitespaces from this line, like that:

si.StartInfo.Arguments = "/C dtexec /f E:\\Package.dtsx /set \\package.variables[FilePath].Value;e:\\testFile.txt"

You should also be able to run your command in cmd.exe:

dtexec /f e:\package.dtsx /set \package.variables[FilePath].Value;e:\testFile.txt

Unless it will work in cmd, it won't work also from your code.

Comments