Friday, October 10, 2008

Working With Backslashes in SSIS

SSIS takes a very standard programming approach when working with backslashes. It treats backslashes as escape characters. Since paths in windows uses the backslash to separate directories, there needs to be some extra thought on how to handle these when building an expression. For example in the following expression window I want the connection string to be c:\test.txt instead when I evaluate it, it becomes "C: est.txt".





The workaround in SSIS is to escape the escape character or in simple terms use two backslashes.
So it looks like this “C:\\test.txt”. The result here is C:\test.txt.

Were things get a little complicated is when your work against a process that also works with the escape character. For example when using the mysql executable to Load data the path to be passed in must look like this:
c:\\test.txt.
Since the escape character only works for the character following the first character after the backslash you need to use four backslashes to represent 2.
"C:\\\\test.txt"

No comments: