In this article, I will show How to Read BLOB data in Oracle using ASP.NET Generic Handler.
Before we getting started to Read BLOB data in Oracle in ASP.Net, let’s first know What’s ASP.NET Generic Handler?
What’s the Generic Handler in ASP.NET?
Some ASP.NET files are dynamic. They are generated with C# code or disk resources. These files do not require web forms. Instead, an ASHX generic handler is ideal to can return an image from a query string, write XML, or any other data.
To know more about Generic Handler, Please check ASP.NET ASHX Handler Tutorial.
Generic Handler VS Web Forms
The WebForms (ASPX) can be used in
- Simple Html Pages.
- ASP.Net Custom Controls.
- Simple Dynamic Pages.
The Handlers (ASHX) can be used with
- Binary files.
- Dynamic Image Views.
- Performance critical web pages.
- XML files.
- Minimal Web Pages.
Read BLOB data in Oracle using Generic Handler in ASP.NET
Steps
Open Visual Studio > Open existing ASP.NET Solution > Add tag within a page that should look like this
<img id="EmpImg"
src="ShowImage.ashx?Account="
alt="" width="100px" height="100px" style="float:right"/>
Note: The image source is a generic handler called ShowImage.ashx.
Create a Generic Handler In Visual Studio
- Open your ASP.Net Web Site and go to File menu > New >Check Generic Handler.
- Rename the generic handler with an appropriate name. In my case, it is ShowImage.
- Click on add, the below-structured file will be shown.
Note: Handler is an interface that includes a function called “ProcessRequest” which will be used to execute the code that has been placed within it.
- In Handler, add System.Data.OracleClient namespace
using System.Data.OracleClient; //Oracle client to can Work with Oracle Database
Learn how to install oracle client at How you can install Oracle Data Provider?
- In “ProcessRequest” function Add the following code to retrieve a BLOB field from OracleDB.
public void ProcessRequest(HttpContext context) {
string Account;
if (context.Request.QueryString["Account"] != null) {
Account = context.Request.QueryString["Account"].ToString();
OracleConnection con = new OracleConnection(OracleConn);
con.Open();
OracleCommand com = con.CreateCommand();
com.CommandText = "(SELECT pi.image img FROM fnd_user fu,per_images pi WHERE fu.user_name = '" + Account.ToUpper() + "' AND fu.employee_id = pi.parent_id)";
OracleDataReader img = com.ExecuteReader();
try {
img.Read();
context.Response.BinaryWrite((byte[]) img[img.GetOrdinal("img")]);
img.Close();
}
catch {}
finally {
con.Close();
}
}
}
- Finally, Make sure that tag source parameters are provided correctly.
- Go back to run the Web Application that should now be working properly.
Conclusion
In conclusion, we have learned how to read blob data in oracle database in ASP.net solution using Generic Handler.
Can u provide full code for above example. Also send the code to my email id vijaystar12@gmail.com