I was creating an SSIS package recently and ran into the “TargetInvocationException: Exception has been thrown by the target of an invocation” error as shown in figure 1 below.
Figure 1: Target Invocation Error
This happened to me a year or so ago, but I think my resolution was to delete the script task and then added it back in. Essentially re-writing all of my script! This time however, I was bound and determined to find the root cause. So, I looked at my code in the script task and didn’t see anything. I removed the variables from the script editor window and added them using the ellipsis. After rerunning the package and having another failure, I went over every single letter in my script. And BAM! I saw what I did wrong. I had a typo in the variable that I was using. After correcting it, my package ran as expected. Instead of having Dts.Variables(“ConnString”).Value.ToString, I had Dts.Variables(“ConnStrng”).Value.ToString. I was missing the “i” in string. Also note that SSIS variables are case sensitive. So, if I had “connstring”, I would have received the same error.
So, be cautious when typing your code and using variables because as you can see, one fat finger can cause the “Target Invocation Exception” to be thrown. Fortunately, this only set me back about 4 minutes, but hopefully you remember this for next time or do a quick search for “TargetInvocationException” and find it even quicker. J
I hope that you have enjoyed this post. If you did, please take just a moment to rate it below! Also, if you don’t already, please be sure to follow me on twitter at @briankmcdonald. Also note that you can subscribe to an RSS feed of my blogs.
Brian K. McDonald, MCDBA, MCSD
Business Intelligence Consultant – Pragmatic Works
Twitter: @briankmcdonald | LinkedIn: http://tinyurl.com/BrianKMcDonald