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

发布于 2024-10-14 09:23:35 字数 1143 浏览 6 评论 0原文

与 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:\Users\User\Desktop\Local_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);
        }
    }

Struggling with a C# Component. What I am trying to do is take a column that is ntext in my input source which is delimited with pipes, and then write the array to a text file. When I run my component my output looks like this:

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

Ive been working with the GetBlobData method and im struggling with it. Any help with be greatly appreciated! Here is the full script:

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:\Users\User\Desktop\Local_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);
        }
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ繥欢鉨o。 2024-10-21 09:23:35

尝试

BlobToString(Row.Options)

使用此功能:

  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-使用-c

Try using

BlobToString(Row.Options)

using this 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;
    }

Adapted from:
http://mscrmtech.com/201001257/converting-microsoftsqlserverdtspipelineblobcolumn-to-string-in-ssis-using-c

念﹏祤嫣 2024-10-21 09:23:35

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

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

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

Another very easy solution to this problem, because it is a total PITA, is to route the error output to a derived column component and cast your blob data to a to a STR or WSTR as a new column.

Route the output of that to your script component and the data will come in as an additional column on the pipeline ready for you to parse.

This will probably only work if your data is less than 8000 characters long.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文