473,748 Members | 10,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

retrieving BLOB from Oracle

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...b;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
OracleConnectio n conn = new
OracleConnectio n(Configuration Settings.AppSet tings["connStr"]);
OracleCommand command = new
OracleCommand(" COFE.GetInspect ionReportByID", conn);
command.Command Type = CommandType.Sto redProcedure;

//params
command.Paramet ers.Add("p_file ID", OracleType.Numb er).Value = reportID;
command.Paramet ers.Add("cur_re sults", OracleType.Curs or).Direction =
ParameterDirect ion.Output; //output

OracleLob blob = null;

//fill blob
conn.Open();
OracleDataReade r dr = command.Execute Reader();

if (dr.Read()) //has row
blob = dr.GetOracleLob (5);

byte[] byteArray = (byte[])blob.Value;

conn.Close();

//response (kitchen sink for tests)
Response.Clear( );
Response.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.AddHea der("content-disposition", "attachment ; filename=" +
report.FileName );
Response.Buffer Output = true;

Response.Binary Write(byteArray );
Response.End();
....however, when excel loads the file, it says its an "unrecogniz able
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

Dec 1 '06 #1
9 7996
anybody? anybody know how to retrieve a binary file out of an Oracle
BLOB column via a proc? c'mon, somebody has to know.....

thanks,
matt

Dec 4 '06 #2
If nobody here seems to have an answer for you, maybe you could
post this to an Oracle group?

Sorry I can't help you.
Robin S.
----------------------------------
<ma**@mailinato r.comwrote in message
news:11******** **************@ l12g2000cwl.goo glegroups.com.. .
anybody? anybody know how to retrieve a binary file out of an Oracle
BLOB column via a proc? c'mon, somebody has to know.....

thanks,
matt

Dec 4 '06 #3
RobinS wrote:
If nobody here seems to have an answer for you, maybe you could
post this to an Oracle group?
yeah thats my next stop. i just figured since this app-code (.NET)
dependant, and not really an Oracle issue, that the .NET groups would
be most on-topic.

thanks,
matt

Dec 4 '06 #4
....i tested this w/ another file format, .PDF. same thing -- the byte
array of the retrieved file matches the original's size-on-disk. when
its saved via the response to disk, it also matches the orig.

however, opening it is impossible. opening it in notepad yields an
empty file, devoid of the normal binary garbage characters.

if somebody could help me confirm the insert/retrieve techniques, id
likely be golden.
matt

Dec 4 '06 #5
nil

ma**@mailinator .com wrote:
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...b;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
OracleConnectio n conn = new
OracleConnectio n(Configuration Settings.AppSet tings["connStr"]);
OracleCommand command = new
OracleCommand(" COFE.GetInspect ionReportByID", conn);
command.Command Type = CommandType.Sto redProcedure;

//params
command.Paramet ers.Add("p_file ID", OracleType.Numb er).Value = reportID;
command.Paramet ers.Add("cur_re sults", OracleType.Curs or).Direction =
ParameterDirect ion.Output; //output

OracleLob blob = null;

//fill blob
conn.Open();
OracleDataReade r dr = command.Execute Reader();

if (dr.Read()) //has row
blob = dr.GetOracleLob (5);

byte[] byteArray = (byte[])blob.Value;

conn.Close();

//response (kitchen sink for tests)
Response.Clear( );
Response.ClearC ontent();
Response.ClearH eaders();
Response.Conten tType = "applicatio n/vnd.ms-excel";
Response.AddHea der("content-disposition", "attachment ; filename=" +
report.FileName );
Response.Buffer Output = true;

Response.Binary Write(byteArray );
Response.End();
...however, when excel loads the file, it says its an "unrecogniz able
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

hey can u tell me how can i save the image in the oracle in blob column
and retrieve from that?thanks in advance...
nil

Dec 5 '06 #6

ma**@mailinator .com wrote:
...however, when excel loads the file, it says its an "unrecogniz able
format". opening it in notepad, its empty. *but*, right-clicking the
file, its size on disk matches the pre-databased version exactly!
figured it out. it had nothing to w/ my retrieval code.

the files were coming out of oracle w/ the correct byte size, but empty
in notepad, because i inserted them incorrectly.

for the insert, i had *sized* the byte array prior to blob-and-insert,
but i hadnt *filled* it! so the insert worked, the retrieval worked,
but the file contents were simply empty.
matt

Dec 5 '06 #7
nil wrote:
hey can u tell me how can i save the image in the oracle in blob column
and retrieve from that?thanks in advance...
nil
well, first follow the link in my OP. if youre using the ms
dataprovider (System.Data.Or acleClient), and not ODP.NET (oracle's data
provider) then its how you do the blob shuffle.

getting the file *out* was much simpler for me:

//conn & command
OracleConnectio n conn = new
OracleConnectio n(Configuration Settings.AppSet tings["connStr"]);
OracleCommand command = new OracleCommand(" Foo.GetFileByID ", conn);
command.Command Type = CommandType.Sto redProcedure;

//params
command.Paramet ers.Add("p_repo rtID", OracleType.Numb er).Value =
reportID;
command.Paramet ers.Add("cur_re sults", OracleType.Curs or).Direction =
ParameterDirect ion.Output; //output

//do it
DataSet ds = new DataSet();
OracleDataAdapt er da = OracleClient.Or acleDataAdapter (command);
da.Fill(ds);

//get file contents from returned data
byte[] fileContents = (byte[])row["FileConten ts"];

Response.Binary Write(fileConte nts );
matt

Dec 5 '06 #8
nil

ma**@mailinator .com wrote:
nil wrote:
hey can u tell me how can i save the image in the oracle in blob column
and retrieve from that?thanks in advance...
nil

well, first follow the link in my OP. if youre using the ms
dataprovider (System.Data.Or acleClient), and not ODP.NET (oracle's data
provider) then its how you do the blob shuffle.

getting the file *out* was much simpler for me:

//conn & command
OracleConnectio n conn = new
OracleConnectio n(Configuration Settings.AppSet tings["connStr"]);
OracleCommand command = new OracleCommand(" Foo.GetFileByID ", conn);
command.Command Type = CommandType.Sto redProcedure;

//params
command.Paramet ers.Add("p_repo rtID", OracleType.Numb er).Value =
reportID;
command.Paramet ers.Add("cur_re sults", OracleType.Curs or).Direction =
ParameterDirect ion.Output; //output

//do it
DataSet ds = new DataSet();
OracleDataAdapt er da = OracleClient.Or acleDataAdapter (command);
da.Fill(ds);

//get file contents from returned data
byte[] fileContents = (byte[])row["FileConten ts"];

Response.Binary Write(fileConte nts );
matt
should i follow the same thing when i want to retrieve image from the
database and what if i am using oracle's provider like msdaora.1.....
so is there any way to do for this provider....tha nks a lot for reply

Dec 6 '06 #9
nil wrote:
should i follow the same thing when i want to retrieve image from the
database and what if i am using oracle's provider like msdaora.1.....
so is there any way to do for this provider....tha nks a lot for reply
dunno, dude. research time.

Dec 6 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
23029
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
0
1259
by: Utilisateur1 | last post by:
Hello, I've a problem retrieving a blob column from oracle. I'm using oledbadapter to fill a dataset like that oledataadap.fill(ds,"query"); I'm also using ColumnMapping to have more friendly column headers in dataset. The Fill method send an error with no explaznation except this "the type is not managed". Has somebody ideas about to solve that ?
4
2159
by: Nau | last post by:
How can I display BLOB(Oracle) data in asp page
11
3930
by: Peter Afonin | last post by:
Hello, I have Word documents stored in the Oracle database in the BLOB field that I need to retrieve. I've found the way of doing it: While dr.Read sName = dr("TE_PM_ATTACH_NAME") bLob = dr.GetOracleLob(1)
0
1899
by: coony | last post by:
Hi everyone, I got an annoying thing going on. I've got an MSSQL db which is filled with different data, used by another program (T-Plan). I should read some table to import in another DB. The DB I have to read, contains als BLOB files. In Excel I created a connection string, can read all fields & values as shown in the DB, but I can't manage to convert the Blobs to Strings (which is the data in the BLOBs). I tried all the next, but...
0
1663
by: Harshadcode | last post by:
Hi, This is HARSHAD, I am creating a project in VB.NET for managing details like photos of criminals. but i am facing problems in converting a image in to filestream so that it can be inserted in to the oracle 10g database using BLOB variable type. if you can help me it will be very helpful.. This is my code: --------------------------------------------------------------------- Imports System
3
2588
by: jackliu | last post by:
Hi there, I have a problem about how to use MS Access insert an image to BLOB field in AS/400? Could anyone provide me VB code for inserting and retrieving BLOB data? Thanks in advance. Regards, Jack
1
3079
by: sana krishna | last post by:
Pls Help me-------------- I use ASP(C#.NET) and oracle. When i retrive image from database .it display error message... System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.Byte'. my code in the show button is.pls anybody help me ,how to retrive and display the image protected void btnshow_Click(object sender, EventArgs e) { DataTable dt = ds.Tables; MemoryStream stream = new...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6074
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.