Save image file text in SQL Varbinary column

  • Thread starter Thread starter Abhijeet Khopade
  • Start date Start date
A

Abhijeet Khopade

Guest
Hi Experts,

I am trying to save all the file contents in SQL Server. Facing issue only when image file with below text is not been able to save in Varbinary column. Any idea how can i store this?


���� JFIF  H H �� C   



    �� C

 �� ]� ��    �� _ 

  !1"2AQ�RSaq���#34BTs����5Ubru��$%Ct�����678DV��c����&���Ee���   �� G   !12AQRq��"3ar���4B���DSb#%5C�$E�cT������   ? ��5��]�q%Xb�2a"
���n�


I am using following code to save files to SQL. When file is directly accessible then using OPENROWSET-

If bFilePath Then
sSql = "INSERT INTO [dbo].[ResultsContent] ([FileContent],[Extension],[MD5])"
sSql &= " SELECT BULKCOLUMN,'" & sExtension & "','" & sMD5 & "'"
sSql &= " FROM OPENROWSET(BULK '" + sFileContent + "', SINGLE_BLOB) AS T"
Else
sSql = "INSERT INTO [dbo].[ResultsContent] ([Extension], [MD5], [FileContent]) SELECT '" & sExtension.Replace("'", "''") & "','" & sMD5 & "', CAST('" & sFileContent.Replace("'", "''") & "' AS VARBINARY(MAX))"
End If

But if file is getting read from Zip file (drive:\downloads\modernuicharts\wiki\downloadWiki.zip\\docs\Home_Screenshot_Silverlight_preview.jpg) I am extracting content of Image file. But error i got is as below-

System.Data.OleDb.OleDbException: Incorrect syntax near '����'." & vbCrLf & "Unclosed quotation mark after the character string '����'." & vbCrLf & "


Is there a way that i can store this as plain text in Varbinary column?


Abhijeet Khopade

Continue reading...
 
Back
Top