I have a varbinary(max) column that I need to bulk import. The data I'm putting into this column is a byte[] in C#. How do I format the data in the comma-delimited file used for bulk import? In other words, how do I convert from a byte[] to a string in a way the bcp utility will accept?

  • Did one of these answers work for you please?
    – gbn
    Commented Aug 27, 2011 at 12:46
  • Can you add sample data please? My answer won't work for me.. :)
    – gbn
    Commented May 17, 2013 at 6:44

3 Answers 3


A varbinary value is of the form 0x01020304 for SQL Server to read.

So your CSV would be


Edit May 2013,

After testing, I can't get this to work with BULK INSERT with or without a format file.

I will post something more when I get it working. I can't delete this answer

  • 2
    Have you used this successfully? On my end, I got "type mismatch" errors until I dropped the hex prefix. "0102" was OK, "0x0101" was not. Perhaps there is a setting somewhere which specifies which method is required. Commented May 15, 2013 at 23:48
  • @JonofAllTrades: hmm I can't get it to work. Playing with format files but that is not working either
    – gbn
    Commented May 16, 2013 at 7:05
  • Which one? If "0x00" is what works for you, then it seems some setting differs between our setups. If "00" is what works for you, and "0x00" does not, then we're both seeing the same thing, and it might make sense to edit your answer. Commented May 16, 2013 at 19:49
  • you should edit answer, as actually '0x1234' doesn't work, but '1234' does
    – Tertium
    Commented Mar 18, 2016 at 17:21

You can use the BCP unicode native format to import/export. Use bcp -n for the export and the WITH (DATAFILETYPE='widenative') clause for import. Click link to read more.


I got it to work. Your varbinary data must be in form 424C4F4220434F4E54454E54 in csv file. And you also must specify the right code-page of the csv file.

I have the following table:

CREATE TABLE [dbo].[BlobTable](
    [id] [int],
    [blobValue] [varbinary](max),
    [textValue] [nvarchar](500)

and bulk import query:

bulk insert dbo.BlobTable
from 'C:\importBlob.csv'
with (DATAFILETYPE = 'char', fieldterminator=',', codepage='1251')

It works nice for the csv file with windows-1251 encoding:

1,424C4F4220434F4E54454E54,english text
2,424C4F4220434F4E54454E54,русский текст

Here the value 424C4F4220434F4E54454E54 is simply BLOB CONTENT in binary form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.