6
votes

I am creating a SSIS package and getting the following error while extracting the data.

Error: The type of the value (DBNull) being assigned to variable "User::dunsId" differs from the current variable type (String). Variables may not change type during execution. Variable types are strict, except for variables of type Object.

dunsId is varchar(150) in the source table which is nullable column and contains Null value. The variable that I have created in SSIS to map it is of type string. I am basically trying to extract all he records and insert it in the destination table that contains column dunsId is varchar(150)

here is my insert query

INSERT INTO Parties (companyId, dunsId, companyName, companyTypeId,companyTypeName,companyStatusTypeId,companyStatusTypeName,simpleIndustryId,simpleIndustryDescription)  
values (companyId, dunsId, companyName, companyTypeId, companyTypeName,companyStatusTypeId,companyStatusTypeName,simpleIndustryId,simpleIndustryDescription)

Parameter mapping enter image description here

variables

enter image description here

design

enter image description here

2
why you need a variable to store the source data? cannot be a directly load? from source to destination? - LONG
What I am trying to do is extract all the data in the first execute sql statement and store it in an object variable. I am then traversing the object in for loop container and trying to execute the insert statement in execute sql task within it. Correct me if I am going wrong anywhere - Tom
hence I have defined the uservariables and done the mappings in the execute sql task to hold the values in it before inserting - Tom
I am not very sure what is the purpose of doing that, for me, you could do in many other ways like what you are trying to do, such as single sql task insert into select * from, or OLE DB source to OLE DB Destination. If you have some reasons with your methods, you could put expression for that variable, which is to use ISNULL to convert NULL - LONG
Where do I set the IsNull, is if where my variables are defined or in parameter mapping etc - Tom

2 Answers

4
votes

Few ways to solve your problem:

  1. Easiest way is change the data type from string to object
  2. From the first Execute SQL task, put ISNULL around the issue column, which will make sure the output is string
  3. Use some alternate ways such as load from Source to Destination in DataFlow task or use one Execute SQL task with INSERT INTO target_table SELECT...FROM Source_table statement

UPDATE

as you mentioned, you are outputting the columns using stored procedure, then you could utilize statement INSERT INTO target_table EXEC your_usp instead of method 3 above

-1
votes

The Variable type for dunsId variable is STRING & you trying to assign a value for this variable NULL at runtime i.e your query returns NULL for column dunsId which is not supported for variable type String please declare it as type Object.

enter image description here