SSIS Error : Object is not an ADODB.RecordSet or an ADODB.Record + Solution

Problem :

I have two script tasks in my SSIS package. The first one saves a string array as a package variable:
// In 1st script task:
String[] astrCustNames = new String[cust_count];

/* ...
 * Some code to add strings to array ...
 */

// Add array to a package variable
Dts.Variables["CustomerNames"].Value = astrCustNames;
The second task should then extract the strings from the variable. In the past, I've done this with a table variable. The same approach won't work for the string array:
// In 2nd script task:
OleDbDataAdapter ole_da = new OleDbDataAdapter();
// Fill the customer names data table
DataTable dtCustNames = new DataTable();
ole_da.Fill(dtCustNames, Dts.Variables["User::CustomerNames"].Value);
The call that fills the data adapter will result in the error "Object is not an ADODB.RecordSet or an ADODB.Record."
The .dtsx package lists the data type as DTS:DataType="13"
The data type of the variable as it is defined in the package is "Object":
// Returns type "Object":
TypeCode cur_type = Dts.Variables["User::CustomerNames"].DataType;

Solution :

Just cast the value to a string array:
String[] astrCustNames = (String[])Dts.Variables["User::CustomerNames"].Value;


Comments

  1. Thanks for sharing the useful infomration.
    We know that Execute SQL Task is an extra ordinary component in Integration Services. We can use one or more variables in Execute SQL Task to pull the information from the database. To pull the values from database, we can use the SQL Statement or stored procedure with the parameters. To understand this functionality and know more at
    Use Variable in Execute SQL Task

    ReplyDelete

Post a Comment

Popular posts from this blog

SSAS : A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running. (Microsoft.AnalysisServices.AdomdClient). + Solution

SSIS Error : Unable to infer the XSD from the XML file. The XML contains multiple namespaces