我正在尝试将现有表转换为其他表。我将多行作为字符串,并使用逗号将其存储在一行下。
我创建了一个数据流任务,并添加了一个脚本组件,该组件将接收字符串并将其转换为blob数据。但是在SQL Server中输出列为nvarchar(max)时出现错误
using System;
using System.Data;
using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
using Microsoft.SqlServer.Dts.Runtime.Wrapper;
[Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
public class ScriptMain : UserComponent
{
private string ComputerName;
private string TimeofLastScanAttempt;
private string CopyofRPMCustom;
Byte buffer;
private bool FirstRow = true;
public override void Input0_ProcessInputRow(Input0Buffer Row)
{
if ((Row.ComputerName == ComputerName &&
Row.TimeofLastScanAttempt == TimeofLastScanAttempt) ||
FirstRow)
{
CopyofRPMCustom += (Row.CopyofRPMCustom_IsNull? "," :
Row.CopyofRPMCustom);
ComputerName = Row.ComputerName;
TimeofLastScanAttempt = Row.TimeofLastScanAttempt;
FirstRow = false;
}
else
{
Output0Buffer.AddRow();
Output0Buffer.TimeofLastScanAttempt = TimeofLastScanAttempt;
Output0Buffer.ComputerName = ComputerName;
Output0Buffer.RPM.AddBlobData(
System.Text.Encoding.Unicode.GetBytes(CopyofRPMCustom ?? ""));
CopyofRPMCustom += (Row.CopyofRPMCustom_IsNull ? "," :
Row.CopyofRPMCustom);
ComputerName = Row.ComputerName;
TimeofLastScanAttempt = Row.TimeofLastScanAttempt;
}
}
public override void FinishOutputs()
{
Output0Buffer.AddRow();
Output0Buffer.TimeofLastScanAttempt = TimeofLastScanAttempt;
Output0Buffer.ComputerName = ComputerName;
Output0Buffer.RPM.AddBlobData(
System.Text.Encoding.Unicode.GetBytes(CopyofRPMCustom ?? ""));
base.FinishOutputs();
}
当我调试此代码时,出现错误:
'Output0Buffer.RPM'引发了'Microsoft.SqlServer.Dts.Pipeline.NoCurrentRowException'类型的异常
“ Output0Buffer.RPM_IsNull”引发了“ Microsoft.SqlServer.Dts.Pipeline.NoCurrentRowException”类型的异常
任务成功,但RPM列为空。其他所有内容都已填充。