hello,
im doing my first ASP.NET app that inserts & retrieves files from Oracle (no need for a discussion on *that*!).
i learned first-hand of the somewhat awkward technique for inserting binary data into an Oracle BLOB column via ADO.NET. since my files are larger than 33k, it seemed had to use this technique:
http://support.microsoft.com/default.aspx?scid=kb;en-us;322796
...in which you fill an OracleLob object and pass it into your BLOB column (via a proc in my case).
now i have to retrieve my blob file, and response it to the user. i imagine the process is something like: 1) get data out of db, 2) convert to working format 3) response to client.
however, im running into hitches. not sure what is wrong. can anyone post snippets of working code for doing this? for retrieval, heres my snippet:
//conn & command
OracleConnection conn = new OracleConnection(ConfigurationSettings.AppSettings["connStr"]);
OracleCommand command = new OracleCommand("COFE.GetInspectionReportByID", conn);
command.CommandType = CommandType.StoredProcedure;
//params
command.Parameters.Add("p_fileID", OracleType.Number).Value = reportID;
command.Parameters.Add("cur_results", OracleType.Cursor).Direction = ParameterDirection.Output; //output
OracleLob blob = null;
//fill blob
conn.Open();
OracleDataReader dr = command.ExecuteReader();
if (dr.Read()) //has row
blob = dr.GetOracleLob(5);
byte[] byteArray = (byte[])blob.Value;
conn.Close();
//response (kitchen sink for tests)
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment; filename=" + report.FileName);
Response.BufferOutput = true;
Response.BinaryWrite(byteArray);
Response.End();
...however, when excel loads the file, it says its an "unrecognizable format". opening it in notepad, its empty. *but*, right-clicking the file, its size on disk matches the pre-databased version exactly!
any idea what im missing?
thanks!
matt