behi behi behi behi - 3 months ago 18
ASP.NET (C#) Question

Why i get error in dtexec command in

I'm new in
,and want to write code to run
sql server
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;
string output = si.StandardOutput.ReadToEnd();

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.


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.