I have a PDF which I need to insert into a SQL Server table's varbinary
column.
I convert the PDF into a byte array using C#
byte[] bytes = File.ReadAllBytes(fileName);
I add a parameter to the SqlCommand
:
SqlParameter fileP = new SqlParameter("@file", SqlDbType.VarBinary);
fileP.Value = bytes;
myCommand.Parameters.Add(fileP);
The stored procedure basically takes a varbinary
parameter and inserts into a table's varbinary
column
create procedure pdfInsert
@file varbinary(MAX)
as
insert ...
I get an error on execution of this procedure.
In the SQL Server profiler I found that the following procedure executes
exec pdfInsert @file = 0x2555... <-- byte array of pdf
The error is
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '40E3'.
In SSMS, when I execute this procedure with single quotes at both of the byte array.
Like this:
exec pdfInsert @file = '0x2555.......'
I get the error:
Implicit conversion from data type varchar(max) to varbinary(max) is not allowed. Use the CONVERT function to run this query.
Just curious to know what wrong am I doing? Any help is much appreciated. Thanks