Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS Script Component: Microsoft.SqlServer.Dts.Pipeline.BlobColumn

Tags:

c#

sql

ssis

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);
        }
    }
like image 994
Zach Avatar asked Jan 27 '11 22:01

Zach


People also ask

What is DTS in SSIS Script task?

The Dts object is an instance of the ScriptObjectModel class. ScriptTask. Defines the classes for the Script task, which lets developers write custom code to perform functions that are not available in the built-in tasks provided by Integration Services.

What is the difference between Script task and Script component in SSIS?

The Script task is configured on the Control Flow tab of the designer and runs outside the data flow of the package. The Script component is configured on the Data Flow page of the designer and represents a source, transformation, or destination in the Data Flow task.

What is a DTS pipeline?

Dts. Pipeline namespace contains managed classes that are used to develop managed data flow components. It contains the PipelineComponent class, which is the base class for managed data flow components, and the PipelineBuffer class, which is the managed implementation of the IDTSBuffer100 interface.

What is SSIS scripting?

SSIS Script component is one data transformation tasks in SQL Server Integration Services (SSIS). SSIS is an integration tool in the Microsoft BI family to extract data from heterogeneous data sources and transform it to your need.


2 Answers

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

like image 52
Nat Avatar answered Sep 30 '22 04:09

Nat


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.

like image 45
user3629139 Avatar answered Sep 30 '22 04:09

user3629139