problem while inserting data into a blob field in vb.net

Radha

New member
Joined
Dec 13, 2005
Messages
1
Programming Experience
Beginner
hi,

I am trying to insert a file in to the oracle blob field using an oracle stored procedure.

please find below the code for the stored procedure

Procedure put_log_file(p_test_key varchar2,p_logfile blob,p_log_file_name varchar2)
is
begin
update
saints_testresult
set log_file=p_logfile,
log_file_name=p_log_file_name
where test_key=p_test_key;
commit;
end
put_log_file;--end of procedure put_log_file

i am calling this stored procedure in the vb.net code.please find below the code in vb.net


PrivateSub PutLogFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PutLogFile.Click
Dim myDBManager AsNew DatabaseManager.DatabaseManager
Dim iResult As Int32
Dim buf AsByte()
Dim fStream As System.IO.FileStream
Dim iLength AsInteger
Dim sFile AsString = "Normal.log"
Dim sFileAndPath AsString = "C:\" & sFile

' ----------------------------------------------
' Put File in the File Stream
fStream = New System.IO.FileStream(sFileAndPath, FileMode.Open, FileAccess.Read)
iLength = fStream.Length - 1
' Set iLength
fStream.Position = 0 ' Set the File Stream Position to 0
buf = NewByte(iLength) {} ' Set the Buffer Length
fStream.Read(buf, 0, iLength) ' Read the FileStream and Put into the Buffer
fStream.Close() ' Close the File Stream
Dim sConn AsString
iResult = myDBManager.PutLogFile("5673", sFile, buf)
If (iResult <> 0) Then
MessageBox.Show("Not Good: " & iResult.ToString, "The Test App")
Else
MessageBox.Show("file inserted")
EndIf
EndSub


Public
Function PutLogFile(ByVal sTestKey AsString, ByVal sLogFilename AsString, ByVal buf AsByte()) AsInteger
Dim cmd AsNew OracleCommand
Dim iResult AsInteger
Dim sExceptionMessage AsString
sFunctionName = "Put Log File"
'---------------------------------------------
' Get the Connction String from the Registry
sConnectionString = ConnString()
If (sConnectionString = "") Then
Return -9003
Else
dbConnection.ConnectionString = sConnectionString
EndIf
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "PKG_RESULTS.PUT_LOG_FILE"
cmd.Connection = dbConnection
cmd.Parameters.Add(
New OracleParameter("p_test_key", OracleType.VarChar)).Value = sTestKey
cmd.Parameters.Add(
New OracleParameter("p_logfile", OracleType.Blob)).Value = buf
cmd.Parameters.Add(
New OracleParameter("p_log_file_name", OracleType.VarChar)).Value = sLogFilename
'---------------------------------------------
' Establishes a connection to the database
Try
dbConnection.Open()
Catch ex As Exception
Return -9001
EndTry
'---------------------------------------------
' Runs the Stored Procedure
Try
iResult = cmd.ExecuteNonQuery()
Catch ex As Exception
sExceptionMessage = ex.ToString
dbConnection.Close()
Return -9002
EndTry
'---------------------------------------------
' Closes the connection to the database
dbConnection.Close()
If (iResult = 1) Then
Return 0
Else
Return iResult
EndIf

EndFunction' PutLogFile


when i call the stored procedure i can insert the file if the size of the file is small ie less than 32k but if i try to insert a large file it gives me an error

System.Data.OracleClient.OracleException: ORA-01460: unimplemented or unreasonable conversion requested

i know for sure that a blob field can store upto 4gb of data .
Thanks in advance

Regards,
Radha
 
Back
Top