SSIS package runs fine manually but throws error via JOB

1

SSIS Package Info
I have a package which manipulate some data(received from an API), writes it into SQL Server Table and also converts it to ADODB Recordset to send it remotely to SAP. The package has no SQL or file connections (I'm connecting and writing into the database via c# script).

Problem
Now, this package runs without error(writes the results into SQL Database Table and Send it to SAP) when I run it from Data Tools. When I deploy it to SQL Server and assign this to a job and run it, it fails.
The error is: The Execute method for the task has the error code 0x80004003 (The value can not be NULL. Parameter name: adodb) returned.
The package runs till the step where it writes the data successfully to SQL table. The error is when it tries to send the data to SAP remotely with ADODB Recordset, which it apparently finds null.

What I tried so far
I have tried building it fresh and deploying it. It had no effect.
I have also changed the protection level of the project which has also no effect on it.
Since I have no SQL connection, the most available answers on SO to this problem are of no help.

More Detail
The entire main process is inside a Script Task. Inside this task, the result of the API is written to the SQL Table:

            string SqlQuery= "INSERT INTO xxx (xx, xx)" +
                                    "VALUES(" +
                                    "'" + val1 + "'," +
                                    "'" + val2 + "')";
            try
            {
                SqlConnection con = new SqlConnection(
                                 "Data Source=xxx;Initial Catalog=xxx;User ID=xx;Password=xx");
                con.Open();

                SqlCommand cmd = new SqlCommand(SqlQuery, con);
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception e)
            {

            }


After this, the value (val1, val2) is converted into recordset:

            ADODB.Recordset result = new ADODB.Recordset();
            ADODB.Fields resultFields = result.Fields;

            resultFields.Append("VAL1_LINE",
                                ADODB.DataTypeEnum.adVarChar,
                                255,
                                ADODB.FieldAttributeEnum.adFldIsNullable,
                                null);

            result.Open(System.Reflection.Missing.Value
                    , System.Reflection.Missing.Value
                    , ADODB.CursorTypeEnum.adOpenStatic
                    , ADODB.LockTypeEnum.adLockOptimistic, 0);


            foreach (string row in stringVar.Split('\n'))
            {
                result.AddNew(System.Reflection.Missing.Value,
                              System.Reflection.Missing.Value);
                resultFields[0].Value = Regex.Replace(row, @"\t", "");
            }

After this, the recordset is sent to the RFC function for SAP.
I don't think that the code above helps as the code has no problem running manually. Also, the script task has no variables.
Any help would be appreciated.

sql-server
ssis
asked on Stack Overflow Aug 22, 2019 by SSharma • edited Aug 22, 2019 by SSharma

1 Answer

1

I could find the error this way:

    string text = e.Message.ToString(); 
    string path = @"path\logFile.txt";
    System.IO.File.AppendAllText(path, text);


I added the above code in all try&catch and found the error to be 'ADODB.FieldsToInternalFieldsMarshaler' in the assembly yxz could not be loaded..
This led me to SO Link.
All I did is: Scipt Task > References > adodb > Right click and click properties > Embed Interop Types > False. This solved my problem.

answered on Stack Overflow Aug 26, 2019 by SSharma

User contributions licensed under CC BY-SA 3.0