日期:2011-11-20  浏览次数:20417 次

 

1、先在WEB应用程序项目中添加引用:Interop.OracleInProcServer

2、Web.config的配置:

<configuration>
  <appSettings>
 
 <!--数据库连接信息配置-->
 <add key="Data Source" value="DB" />
 <add key="User ID" value="USER" />
 <add key="Password" value="000000" />
 <add key="Max Pool Size" value="100" />
 <add key="Min Pool Size" value="0" />
 <add key="Pooling" value="true" />
 
  </appSettings>

……

3、Global.asax中创建OracleSession对象,代码如下:

using System;
using System.Collections;
using System.ComponentModel;
using System.Web;
using System.Web.SessionState;

namespace SparePart
{
 /// <summary>
 /// Global 的摘要说明。
 /// </summary>
 public class Global : System.Web.HttpApplication
 {
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.IContainer components = null;
  static public OracleInProcServer._OraSessionClassClass OraSession;
  static public OracleInProcServer.OraDatabase OraDataBase;

  public Global()
  {
   InitializeComponent();
  } 
  
  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)
  {
   
  }
   
  #region Web 窗体设计器生成的代码
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.components = new System.ComponentModel.Container();
  }
  #endregion
 }
}

4、简单应用(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;