With SQL Server 2008, I have a stored procedure that accepts a VarBinary parameter. While the parameter is in memory, I would like to write it to the %temp% directory of the SQL Server.
How can I go from memory blob (it came as a byte[] from a C# app) to text file? The blob does not exist in any disk-resident table.
I am leaning towards having the TSQL sproc call a CLR stored procedure, which so far looks (mostly) like the below.
Problem #1 is that I think the inputBytes[] is stuck at 8k input size.
Problem #2 is that I can't seem to come up with some decent SQL that passes a varbinary value as a parameter so I can test this within Management Studio or VS DB unit test.
public static void FileWrite( string inputName , byte[] inputBytes )
using (FileStream fileStream = new
FileStream(Environment.GetEnvironmentVariable("TEMP") + "\\" + inputName,
FileMode.OpenOrCreate, FileAccess.Write))
{
using ( BinaryWriter binaryWriter = new BinaryWriter(fileStream))
{
binaryWriter.Write( inputBytes );
}
}
Thanks.