Reputation: 534
I need to get data from my SQL Task to a DataTable object using a script task to generate an email. But when I try to fill the data using OLEDB Adapter fill task, it generates an error:
OleDbDataAdapter Internal error: invalid row set accessor: Ordinal=1 Status=UNSUPPORTEDCONVERSION
Screenshot
as above,
public void Main()
{
// TODO: Add your code here
DataTable dt = new DataTable();
String message = "";
OleDbDataAdapter adapter = new OleDbDataAdapter();
if (Dts.Variables.Contains("onErrorList") == true)
{
try
{
try
{
adapter.Fill(dt, Dts.Variables["onErrorList"].Value);
} catch (Exception e)
{
MessageBox.Show(e.Message);
}
foreach (DataRow row in dt.Rows)
{
message = message + "\n" + "Error Time : " + row["message_time"] + "\n" + "Execution Path : " + row["executionpath"] + "\n" + "Error : " + row["MESSAGE"];
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
}
message = Dts.Variables["executionMessage"].Value + "\n" + message;
try {
sendMail("[email protected]", "Error in ETL ", message);
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Mail Sending Failed");
Dts.TaskResult = (int)ScriptResults.Failure;
}
}
#region ScriptResults declaration
/// <summary>
/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
///
/// This code was generated automatically.
/// </summary>
enum ScriptResults
{
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
};
#endregion
this line is where the error has been generated:
adapter.Fill(dt, Dts.Variables["onErrorList"].Value);
and SQL Code I used to get the values
SELECT message_time,CAST(execution_path AS NVARCHAR(100)) AS executionpath , MESSAGE
FROM (
SELECT em.*
FROM SSISDB.catalog.event_messages AS em
WHERE em.operation_id = (SELECT MAX(execution_id) FROM SSISDB.catalog.executions)
-- AND event_name NOT LIKE '%Validate%'
)q
WHERE event_name = 'OnError'
ORDER BY message_time DESC
Result set mapping to variable
Please help me on this.
Upvotes: 5
Views: 5916
Reputation: 37313
First of all, make sure that Dts.Variables["onErrorList"].Value
contains a valid recordset and it is of type System.Object
.
In addition, I think that OledbDataAdapter
has some limitations while reading from SQL since not all data types are supported i.e. nvarchar(max)
Similar issue
Upvotes: 0
Reputation: 3591
I am doing this to import a result set from SSIS variable to a data table to use later in my code. This is how I am doing it.
Your SSIS variable must be Object Datatype. If not you need to use that first.
Then you use c# to do this to get the data and convert it to the adapter like below (instead of converting directly to an adapter like you are trying to do):
// import SSIS variable of object type
Object OBJDataTableValidFieldListFull = Dts.Variables["User::SSISVariableObject"].Value;
// create datatable variable and dataadpapter
DataTable dtValidFieldListFull = new DataTable();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
// fill datatable from variable passed from SSIS Object type
dataAdapter.Fill(dtValidFieldListFull, OBJDataTableValidFieldListFull);
Upvotes: 2