I have to pass parameters to DTEXEC utility through ASP.NET code. I am using the process.start()
method to trigger the SSIS package execution.
String 1
dtexec /file C:\ssis\pkg1.dtsx
/conn "MyConnectionManager";"\"Data Source=localhost\TestSQL2008R2;Initial Catalog=ConnDB;Integrated Security=SSPI;\""
String 2
/file C:\ssis\pkg1.dtsx
/conn "MyConnectionManager;Data Source=localhost\TestSQL2008R2;Initial Catalog=ConnDB;Integrated Security=SSPI;"
The above command line arguments are generated while manually executing the package through DTEXEC utility. However, I need to pass through this command line to process.start()
method in ASP.NET using C#.
How can I represent the above command line within C# string statement? In other words, how do I escape the special characters by making use of @
character and pass a valid statement to process.start()
?
I didn't test these, but the following should do it.
If you go the old fashioned route like I've shown above, you just need to escape
\
(because that IS your escape char) and"
with a\
anywhere in the string. If you use ver batim like the other answer suggests, it will be easier to read and maintain.A verbatim string literal is probably easiest to use for hard coding such strings.
You only need to double up every inner
"
:And:
With "regular" strings, you would need to escape each
"
and\
in the original with a\
before them.At the risk of a downvote for being off topic, you have a better mechanism than calling the dtexec executable. Since you're in .net, use the existing object model. It's far more powerful than the limited abstraction provided through dtexec.
Rough cut of the code would look like