I need to read data row from SQL Server 2008. The type of one of the columns is VARBINARY(MAX)
. In C# I want to use out parameter to read it (and given scenario satisfies the needs mostly).
But I need to specify the parameter variable size to fill the C# variable. Here I assume that 8000 is enough... But who knows:
database.AddOutParameter(command, "vbCertificate", DbType.Binary, 8000);
So the questions are:
INSERT INTO #TempTable(PK, VarBinaryColumn) SELECT PK, VarBinaryColumn FROM dbo. YourPermanentTable; If you need to convert the varbinary data back to the original file text format in T-SQL, you can use CAST or CONVERT to convert to varchar or nvarchar as long as the data was originally ASCII or Unicode.
varbinary [ ( n | max ) ] max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for varbinary is binary varying.
VARBINARY is an SQL data type, nothing to do with C#.
SQL VarBinaryMax. The VARBINARY data type holds variable-length binary data. Use this type when the data is expected to vary in size. The maximum size for VARBINARY is 8,000 bytes. As an aside, the word VARBINARY stands for varying binary.
The max size for VARBINARY(MAX)
is 2 GB of data - 2'147'483'648 bytes.
In your case, when defining it in C#, I would recommend using int.MaxValue
as the value to provide.
And yes, if you want to get the array of bytes back from the SQL Server 2008 table, then you can most definitely use an out
parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With