Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a String to a BlobColumn in SSIS

So I have a column in my SSIS Script Called Data which is of type BlobColumn

I want to assign this column to a string value.

I do the following:

Row.Data = "MyString";

but I get the following error:

Cannot implicitly convert type 'string' to Microsoft.SqlServer.Dts.Pipeline.BlobColumn

So how do I assign a BlobColumn to a String value?

like image 468
User1 Avatar asked Dec 17 '25 14:12

User1


2 Answers

using the answer provided for Converting a string to byte-array without using an encoding (byte-by-byte)

I did the following:

Row.Data.AddBlobData(GetBytes("MyString"));

Where:

byte[] GetBytes(string str)
{
    byte[] bytes = new byte[str.Length * sizeof(char)];
    System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
    return bytes;
}
like image 200
User1 Avatar answered Dec 19 '25 04:12

User1


First, you must decide in which encoding you are going to encode your string. If you don't care, I recommend using:

  • Little Endian UTF-16 for performance, since .NET strings are stored in that encoding

    System.Text.Encoding.Unicode.GetBytes("MyString");
    
  • UTF-8 for storage

    System.Text.Encoding.UTF8.GetBytes("MyString");
    

Consider reading more about encoding here: Character Encoding in .NET

You should NOT use the answer provided here . Read the whole discussion there to understand why. The answer is for a very specific use case and a somewhat educational one.

like image 39
Marco Curvello Avatar answered Dec 19 '25 04:12

Marco Curvello



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!