SQL Server data issue with blob/image
-
Wednesday, December 26, 2012 11:12 AM
Hi
I am trying to set the value of image data type in sql server 2008 from blob data. Using setBlob, setBinaryStream etc sets value in database as "Err" rather than binary values. If i use setBytes() then it's setting values. I was referring to following url
http://msdn.microsoft.com/en-us/library/ms378680.aspx
It says that i can use setBlob,setBinaryStream etc then why i am not able to insert using setBinaryStream or is there any way i can find out why this error is coming or root cause of the error.
Blob data which i am receiving(trying to set as an image) is proper because i tried to create image file of it and is working fine.
Thanks,
Mehul
All Replies
-
Wednesday, May 15, 2013 8:31 AM
Hey In what language are you working . ?
we are using blob fields for storing files aswell
herer is the sub that we use (VB.net)
'The Call on save btn on webpage, using fileupload component(dev. .net)
Add(_ClientUID, Me.FileItem.PostedFile, FileItem.FileBytes, ddlFolder.SelectedValue, txtDescription.Text)
'The Sub
Public Function Add(ByVal ClientUID As String, ByVal FileObject As System.Web.HttpPostedFile, ByVal FileBlob As Byte(), ByVal FolderUID As String, Optional ByVal Description As String = "") As Boolean
Dim ReturnOutPutList As New ArrayList()
Dim Result As String = ""
Try
Dim localSQLServer As New SQLServer(SolveIT.Security.ConnectionStrings.SQLConnectionString)
localSQLServer.AddParameter("@ClientUID", ClientUID, SQLServer.SQLDataType.SQLString)
localSQLServer.AddParameter("@FileName", SolveIT.SupportObjects.Stringhandling.CleanFilename(FileObject.FileName), SQLServer.SQLDataType.SQLString)
localSQLServer.AddParameter("@ContentType", FileObject.ContentType, SQLServer.SQLDataType.SQLString)
localSQLServer.AddParameter("@FileSize", FileObject.ContentLength, SQLServer.SQLDataType.SQLInteger)
localSQLServer.AddParameter("@BLOB", FileBlob, SQLServer.SQLDataType.SQLImage)
localSQLServer.AddParameter("@Description", Description, SQLServer.SQLDataType.SQLString)
localSQLServer.AddParameter("@FolderUID", FolderUID, SQLServer.SQLDataType.SQLString)
localSQLServer.AddParameter("@FileUID", , SQLServer.SQLDataType.SQLString, 36, ParameterDirection.Output)
ReturnOutPutList = localSQLServer.runSPOutput("Common_File_Add")
Result = ReturnOutPutList.Item(0)
localSQLServer.Dispose()
localSQLServer = Nothing
Catch localException As Exception
'Was there an excepiton?
End Try
If Result <> "" Then
Me.Load(ClientUID, Result)
Return True
Else
Return False
End If
End Function'The SP
create PROCEDURE [dbo].[Common_File_Add]
-- Add the parameters for the stored procedure here
@ClientUID uniqueidentifier,
@FileName Nvarchar(250),
@ContentType nvarchar(100),
@FileSize bigint,
@BLOB image,
@Description nvarchar(2000),
@FolderUID uniqueidentifier,
@FileUID as uniqueidentifier output
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
Declare @TempUID uniqueidentifier;
set @TempUID = NewID()
-- Insert statements for procedure here
INSERT INTO [Common_File]
(
Common_Client_UID,
Common_File_UID,
Common_File_FileName,
Common_File_ContentType,
Common_File_Size,
Common_File_BLOB,
Common_File_Description,
Common_Folder_UID
)
VALUES
(
@ClientUID,
@TempUID,
@FileName,
@ContentType,
@FileSize,
@BLOB,
@Description,
@FolderUID
)
Select @FileUID = @TempUID
END
I hobe this makes sens to you ;)/Jacob Ipsen
-
Tuesday, May 21, 2013 2:02 PMModerator
Hello,
I suppose that you are using a JDBC 4.0 driver.
Have you solved your problem ?
I provide you the following link ( as I am not a specialist of this kind of driver, I am not sure that it could help you ) :
http://msdn.microsoft.com/en-us/library/ms378715.aspx
Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

