I have encountered a type problem. I have in SQL Server table with this structure
create table dbo.DataWithCompressedXML
(
ID int not null,
Data varbinary(max) not null,
)
The data looks like:
0x0BC9C82C5600A2448592D4E21285E292A2CCBC74454500
Then I want take this value to C# to decompress, for decompress I use function near, after decompress I see the text like (This is a test string!!), but I can't understand in what type I must take my variable value from DB, and then use my function this is a test string!
public static SqlBytes BinaryDecompress(SqlBytes input)
{
if (input.IsNull)
return SqlBytes.Null;
int batchSize = 32768;
byte[] buf = new byte[batchSize];
using (MemoryStream result = new MemoryStream())
{
using (DeflateStream deflateStream =
new DeflateStream(input.Stream, CompressionMode.Decompress, true))
{
int bytesRead;
while ((bytesRead = deflateStream.Read(buf, 0, batchSize)) > 0)
result.Write(buf, 0, bytesRead);
}
return new SqlBytes(result.ToArray());
}
}