<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data.OleDb" %>
<script language="C#" runat="server">
    void Session_Start(Object Sender, EventArgs e){
	//取得目前用户
	Session["nowUser"]=Request.ServerVariables["REMOTE_HOST"];
	string f="server=localhost;uid=sa;database=master";
	SqlConnection NowConn1 = new SqlConnection(f);//连至Master数据库
	SqlCommand re = new SqlCommand();
	re.Connection=NowConn1;
	re.CommandText="sp_databases";
	re.CommandType = CommandType.StoredProcedure;
	SqlDataReader k;
	re.Connection.Open();
	k=re.ExecuteReader();//执行名为sp_databases的StoreProcedure
	while(k.Read()){//逐一处理及判断数据库名称
		if(k.GetString(0)=="Northwind"){
			string a="server=localhost;uid=sa;";
			a+="database=Northwind";
			SqlConnection NowConn2 = new SqlConnection(a);
			Session["NowSQLNor"]=NowConn2;
		}
		else if(k.GetString(0)=="StockSQL"){
			string b="server=localhost;uid=sa;";
			b+="database=StockSQL";
			SqlConnection NowConn3 = new SqlConnection(b);
			Session["NowSTKSQL"]=NowConn3;
		}
		else if(k.GetString(0)=="EmploySQL"){
			string c="server=localhost;uid=sa;";
			c+="database=EmploySQL";
			SqlConnection NowConn4 = new SqlConnection(c);
			Session["NowEmpSQL"]=NowConn4;
		}
		else if(k.GetString(0)=="master"){
			string d="server=localhost;uid=sa;";
			d+="database=Master";
			SqlConnection NowConn5 = new SqlConnection(d);
			Session["NowMaster"]=NowConn5;
		}
	}
    }
    void Application_BeginRequest(Object Sender, EventArgs e){
	string x=Request.ServerVariables["PATH_TRANSLATED"];
	string y=x.Remove(0,x.Length-11);
	if(y=="Usegbl.aspx"){
		Response.Write(Request.ServerVariables["REMOTE_HOST"]);
        	Response.Write("执行请求中...<br>");
	}
    }
    void Application_EndRequest(Object Sender,EventArgs e){
//	X=Request.ServerVariables("PATH_TRANSLATED")
//	IF Instr(x,"Usegbl.aspx") > 0 Then
//		Response.Write("执行请求完毕...")
//	End if
}
</script>

