Calling Command

I know I am supposed to be using (and loving) power shell, but I ran across a problem this weekend and the good-old command window worked fine.  I was building a one-click application that moved data from one location to another and then manipulating the data.  As part of the workflow, I created a DTS/SSIS package.  To execute this package, I used the following code to shell out to the command prompt and fire up the package:

            String sourceConnectionString = CreateSourceConnectionString();
            String targetConnectionString = CreateTargetConnectionString();

            Process process = new Process();
            process.StartInfo.FileName = "cmd";
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.AppendFormat(@" /F");
            stringBuilder.AppendFormat(@" TransferAllTables.dtsx");

            stringBuilder.AppendFormat(" /Conn {0};\"{1}\"", "SourceConnectionOLEDB", sourceConnectionString);
            stringBuilder.AppendFormat(" /Conn {0};\"{1}\"", "DestinationConnectionOLEDB", targetConnectionString);
            process.StartInfo.Arguments = stringBuilder.ToString();


I also want to thank my friend Ian (who doesn’t have a blog yet so I can’t point you to him) for mentioning  the StringBuilder.AppendFormat() function.  Append() + String.Format() in 1 place.  Nice! Thanks  Ian!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: