I’m looking to take the results of a report run (a PDF file from Crystal Reports), serialize it, stick it into a varbinary field, and then later be able to deserialize it and present it back to the user.
For now I have to just plain old ADO .NET (SqlClient, SqlCommand, etc.)
Are there any pitfalls to this? What is the basic syntax to accomplish this given the fact that I would know the path on the local machine where the PDF file was currently saved?
EDIT: Just seen in the MSDN documentation that Image is going to be removed. Better use use VARBINARY(MAX). (Hey I did not know that).
MY OLD ANSWER: VARBINARY has a limit of 8 KB. Can be too small to store PDF’s. You’d better use the IMAGE datatype.
Use parameters to insert/select your data via the SqlCommand, and you can use just plain SQL like any ordinary field.
The data you pass into the image field is an array of bytes.
Edit 2: Since you are using C#, you should retrieve the data using a DataReader. To create the DataReader use the SequentialAccess flag on the SqlCommand.ExecuteReader, to prevent the data being read into memory too early.