Csharp/C#教程:SSIS脚本组件:Microsoft.SqlServer.Dts.Pipeline.BlobColumn分享


SSIS脚本组件:Microsoft.SqlServer.Dts.Pipeline.BlobColumn

在C#组件中苦苦挣扎。 我想要做的是在我的输入源中使用ntext的列,该列用管道分隔,然后将数组写入文本文件。 当我运行我的组件时,我的输出如下所示:

DealerID,StockNumber,Option 161552,P1427,Microsoft.SqlServer.Dts.Pipeline.BlobColumn 

我一直在使用GetBlobData方法,我正在努力解决它。 任何帮助都非常感谢! 这是完整的脚本:

 public override void Input0_ProcessInputRow(Input0Buffer Row) { string vehicleoptionsdelimited = Row.Options.ToString(); //string OptionBlob = Row.Options.GetBlobData(int ; //string vehicleoptionsdelimited = System.Text.Encoding.GetEncoding(Row.Options.ColumnInfo.CodePage).GetChars(OptionBlob); string[] option = vehicleoptionsdelimited.Split('|'); string path = @"C:UsersUserDesktopLocal_DS_CSVs"; string[] headerline = { "DealerID" + "," + "StockNumber" + "," + "Option" }; System.IO.File.WriteAllLines(path + "OptionInput.txt", headerline); using (System.IO.StreamWriter file = new System.IO.StreamWriter(path + "OptionInput.txt", true)) { foreach (string s in option) { file.WriteLine(Row.DealerID.ToString() + "," + Row.StockNumber.ToString() + "," + s); } } 

尝试使用

 BlobToString(Row.Options) 

使用此function:

  private string BlobToString(BlobColumn blob) { string result = ""; try { if (blob != null) { result = System.Text.Encoding.Unicode.GetString(blob.GetBlobData(0, Convert.ToInt32(blob.Length))); } } catch (Exception ex) { result = ex.Message; } return result; } 

改编自: http : //mscrmtech.com/201001257/converting-microsoftsqlserverdtspipelineblobcolumn-to-string-in-ssis-using-c

此问题的另一个非常简单的解决方案,因为它是一个完整的PITA,是将错误输出路由到派生列组件,并将blob数据作为新列转换为STR或WSTR。

将其输出路由到脚本组件,数据将作为管道上的附加列进入,以供您解析。

这可能仅在您的数据长度少于8000个字符时才有效。

上述就是C#学习教程:SSIS脚本组件:Microsoft.SqlServer.Dts.Pipeline.BlobColumn分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1009531.html

(0)
上一篇 2021年12月29日
下一篇 2021年12月29日

精彩推荐