I am trying to read a blob from an Oracle database. The GetFileContent function takes p_file_id as a parameter and returns a BLOB. BLOB is a DOCX file that needs to be written somewhere in a folder. But I can not understand how to read BLOB. Something is definitely stored in the return_value-paramater parameter after
OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
The value is {byte [9946]}. But I get an error on execution
long retrievedBytes = reader.GetBytes(1, startIndex, buffer, 0, ChunkSize);
It states that an InvalidOperationException was detected: "There is no data for a row or column."
Here is the code:
cmd = new OracleCommand("GetFileContent", oraCon); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("p_file_id", OracleType.Number).Direction = ParameterDirection.Input; cmd.Parameters[0].Value = fileID; cmd.Parameters.Add("return_value", OracleType.Blob).Direction = ParameterDirection.ReturnValue; cmd.Connection.Open(); OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess); reader.Read(); MemoryStream memory = new MemoryStream(); long startIndex = 0; const int ChunkSize = 256; while (true) { byte[] buffer = new byte[ChunkSize]; long retrievedBytes = reader.GetBytes(1, startIndex, buffer, 0, ChunkSize);
How can I read a blob from a function?
c # oracle blob
Kasper Hansen
source share