Search code examples
sql-server-2008ssisssis-2008

The type of the value being assigned to variable differs from the current variable type


My SSIS package fails with the error:

The type of the value being assigned to variable differs from the current variable type.

I declared a variable of type string and corresponding column name in SQL table is varchar(33). If I use data type as object it succeeds but again i need to use the variable value in an expression for connection string and there object type is not supported.

Please help me how to proceed.

Note: The goal of my SSIS package is to get server list from a table (that's where it fails) and execute some script with a foreach loop container in all the servers.


Solution

  • If I'm reading your question right, what you actually need are two variables: one is an Object variable that receives the data from your SQL table, and one is a String value that you will pass to your ForEach loop.

    The difference between them is that your Object variable can hold multiple rows, while your String value can only hold a single item at a time. What you will do is declare an Object variable, populate it with a list of the servers, then use a ForEach loop to step through each item in the list, feeding the values one at a time to your String variable. You will then use the String variable to set up the script you mentioned, and execute it once per server.

    For further reading, there is an excellent walkthrough here that will give you screenshots and examples of what I am talking about.