I used the code below to fill a data table -
OleDbDataAdapter oleDA = new OleDbDataAdapter();
DataTable dt = new DataTable();
oleDA.Fill(dt, Dts.Variables["My_Result_Set"].Value);
I get the error -
Error: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Object is not an ADODB.RecordSet or an ADODB.Record.
Parameter name: adodb
at System.Data.OleDb.OleDbDataAdapter.FillFromADODB(Object data, Object adodb, String srcTable, Boolean multipleResults)
at System.Data.OleDb.OleDbDataAdapter.Fill(DataTable dataTable, Object ADODBRecordSet)
at ST_34944nkdfnfkdffk333333.csproj.ScriptMain.Main()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()
Why do I get this error ? I have used the exact same code before and it never gave me any problems.
In a script task, I created a datatable called DtUsers, created columns in the datatable, added rows and assigned values to the row cells. I then stored this datatable in an object variable called activeDirectoryUsers:
I then created a Data Flow and added a Source Script Component. I tried to use
Fill()
and received the same error as the OP.The solution for me was twofold:
Add the DtUsers datatable to a DataSet and then store the DataSet in the object variable.
In the Source Script Component, create a new DataSet and cast the object variable to type DataSet, and assign it to the DataSet:
This article led me to this solution.
I think you need to append the
.ToString()
method when you perform the.Fill()
.Something like this:
From the documentation here:
It looks like in your implementation, you are trying to pass an unexpected type to the
.Fill()
method.In my case the problem was resolved changing the code and using DataSet for Fill instead DataTable
This error happens when you have not connected two components in SSIS. See image - The execute SQL task produces an ADO record set which will be consumed by the C# script. That ADO is stored in an SSIS object variable (not shown in image) and is picked up by the C# script which I mentioned in my question.
Below worked for me without Fill.
I had the same or very similar error and the problem was in the Execute SQL Task that loaded the Object variable that I was passing in, I had the ResultSet set to Single row and it needed to be Full result set.