Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Escape characters not escaping...

$
0
0

Hello, all,

I'm seeing some very bizarre behavior in SSIS 2008 R2.  I have a variable that is used as the source for a WMI Data Reader query.  The Data Reader task is inside a foreach loop.  The foreach loop reads in file names from a directory and the WMI source variable is built the variable used to hold the file name in the loop.

What's happening is, the escape characters I am using in the expression to keep the double quotes is being used when the variable is resolved.  Here is some code to show what's happening:

Variable @[User::vFindFile] - string, evaluated as an expression:

"SELECT Name FROM CIM_Datafile WHERE Name = \"" + @[User::vFileName]  + "\" AND CreationDate < \"" +  @[User::vTestDate] + "\""

Variable @[User::vTestDate] - string, evaluated as an expression, used to build date/time WMI uses:

(DT_WSTR, 4)DATEPART( "yyyy", @[User::vFileCreateDate]  ) +  (DT_WSTR, 2)  DATEPART( "mm", @[User::vFileCreateDate]  ) +  (DT_WSTR, 2) DATEPART( "dd", @[User::vFileCreateDate]  ) + "000000.000000-240"

Variable @[User::FileCreateDate] - datetime, used to set the date/age for which files I want to select

DATEADD( "dd", -20, GETDATE() )

What I am expecting the query in vFindFile to look like when everything is evaluated is this:

SELECT Name FROM CIM_Datafile WHERE Name = "I:\\bak\\file1.txt" AND CreationDate < "20121127000000.000000-240"

And that is what I see when I test the evaluation when I build the expression (minus the file name because that is populated from the foreach loop).  However, the WMI Data Reader task is failing with an error,

Error: 0xC002F304 at WMI Data Reader Loop, WMI Data Reader Task: An error occurred with the following error message: "Invalid query ".

When I set all the break points, step thru it and look at all the variables, I noticed that the query is actually coming out as:

SELECT Name FROM CIM_Datafile WHERE Name = \"I:\\bak\\file1.txt\" AND CreationDate < \"2012119000000.000000-240\"

For some reason, the slashes that preceed the double-quotes are not being removed.  Has anyone seen this before?  Am I doing something wrong that I am just missing?  I thought this was pretty straight forward and have done with many times before, although not with a WMI Data Reader task.  Maybe there's something specific to this I'm not aware of.

Thanks for taking a look at this....

Pete


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>