我需要使用脚本任务将数据从 SQL 任务获取到 DataTable 对象以生成电子邮件。但是当我尝试使用 OLEDB 适配器填充任务填充数据时,它会生成错误:
OleDbDataAdapter 内部错误:行集访问器无效:Ordinal=1 Status=UNSUPPORTEDCONVERSION
截屏
如上,
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] /cdn-cgi/l/email-protection", "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
这一行是产生错误的地方:
adapter.Fill(dt, Dts.Variables["onErrorList"].Value);
和我用来获取值的 SQL 代码
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
variable type
请帮我解决这个问题。
我这样做是为了将结果集从 SSIS 变量导入到数据表中,以便稍后在我的代码中使用。我就是这样做的。
您的 SSIS 变量必须是对象数据类型。如果没有,您需要先使用它。
然后,您使用 c# 来获取数据并将其转换为适配器,如下所示(而不是像您尝试那样直接转换为适配器):
// 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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)