At this article, I will demonstrate How to
Read BLOB field from Oracle using Generic Handler in ASP.NET.
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.
It can return an image from a query string, write XML, or any other data.to know more about Generic Handler check this.
Generic Handler (ASHX) VS Web Forms (ASPX)
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.
Steps:
Get BLOB field from Oracle using Generic Handler in ASP.NET
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
- 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.
Can u provide full code for above example. Also send the code to my email id vijaystar12@gmail.com
LikeLike