简体   繁体   中英

Inserting byte array vs Encoded text in SQL Server

I get stream of BSON data in my WebApi. I need to store the stream into database. Should I store the data in varbinary column or encode the data into UTF8 encoding & then save?

I am using entity framework for data access. If you suggest saving in binary, which data type should be preferred binary or byte ?

BSON is binary. You should ideally store it in a varbinary(...) column ( varbinary(max) is the most convenient). Do not consider UTF-8: it is incorrect to use UTF-8 to convert arbitrary binary to a string; that is encoding backwards and the only guaranteed output is corrupt data . If you must store binary in a character-based field ( [n][var]char(...) ), then use base-64.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM