asp.net|object|oracle| Data | database
1. Add a reference to the Web application project first: Interop.oracleinprocserver
2, the Web.config configuration:
<configuration>
<appSettings>
<!--database connection information configuration-->
<add key= "Data Source" value= "DB"/>
<add key= "User ID" value= "user"/>
<add key= "Password" value= "000000"/>
<add key= "Max Pool Size" value= "/>"
<add key= "Min Pool Size" value= "0"/>
<add key= "Pooling" value= "true"/>
</appSettings>
......
3, Global.asax Create the Oraclesession object, the code is as follows:
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Web;
Using System.Web.SessionState;
A summary description of the
namespace Sparepart
{
///<summary>
///Global.
///</summary>
public class Global:System.Web.HttpApplication
{
<summary>
///A required designer variable.
///</summary>
private System.ComponentModel.IContainer components = null;
static public Oracleinprocserver._orasessionclassclass orasession;
static public oracleinprocserver.oradatabase oradatabase;
public Global ()
{
initializecomponent ();
&NBSP;&NBSP;}&NBSP
protected void Application_Start (Object sender, EventArgs e)
{
orasession=new oracleinprocserver._orasessionclassclass ();
orasession.createdatabasepool (Convert.ToInt32 ( system.configuration.configurationsettings.appsettings["Min Pool Size"]), Convert.ToInt32 ( system.configuration.configurationsettings.appsettings["Max Pool Size"], 30, system.configuration.configurationsettings.appsettings["Data Source"], system.configuration.configurationsettings.appsettings["User ID"]+ "/" + system.configuration.configurationsettings.appsettings["Password"],0);
}
protected void Session_Start (Object sender, EventArgs e)
{
session["oradatabase"] = (oracleinprocserver.oradatabase) orasession.get_getdatabasefrompool (30);
}
protected void Application_BeginRequest (Object sender, EventArgs e)
{
}
protected void Application_EndRequest (Object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest (Object sender, EventArgs e)
{
}
protected void Application_Error (Object sender, EventArgs e)
{
}
protected void Session_End (Object sender, EventArgs e)
{
Oracleinprocserver.oradatabase oradatabase= (oracleinprocserver.oradatabase) session["OraDatabase"];
Oradatabase.close ();
session["Oradatabase"]=null;
}
protected void Application_End (Object sender, EventArgs e)
{
}
Code generated #region the Web forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
this.components = new System.ComponentModel.Container ();
}
#endregion
}
}
4. Simple Application (Default.aspx):
Using System;
Using System.Collections;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.HtmlControls;
Namespace Sparepart
{
<summary>
Summary description of the WebForm1.
</summary>
public class Default:System.Web.UI.Page
{
private void Page_Load (object sender, System.EventArgs e)
{
Place user code here to initialize page
Oracleinprocserver.oradatabase oradatabase= (oracleinprocserver.oradatabase) session["OraDatabase"];
Oracleinprocserver.oradynaset Orars;
Oracleinprocserver.orafields Orafs;
Oracleinprocserver.orafield Oraf;
Orars= (Oracleinprocserver.oradynaset) oradatabase.get_createdynaset ("SELECT * from Test", 0);
Oradatabase.executesql ("INSERT into Test (Username,password) VALUES (' You ', ' Password ')");
Response.Write ("<table border=1>");
while (! orars.eof)
{
Orafs= (oracleinprocserver.orafields) orars.fields;
oraf= (Oracleinprocserver.orafield) orafs["username"];
Response.Write ("<tr><td> name </td><td>");
Response.Write (Oraf.value);
Response.Write ("</td><td> password </td><td>");
oraf= (Oracleinprocserver.orafield) orafs["password"];
response.write (Oraf.value);
response.write ("</td></tr>");
orars.movenext ();
}
response.write ("</table>");
orars.close ();
}
Code generated #region the Web forms Designer
Override protected void OnInit (EventArgs e)
{
//
CodeGen: This call is required for the ASP.net Web forms Designer.
//
InitializeComponent ();
Base. OnInit (e);
}
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
}
}