<%@ Import NameSpace="System"%>
<%@ Import NameSpace="System.Data"%>
<%@ Import NameSpace="System.Data.SqlClient"%>
<%@ Import NameSpace="System.Web"%>
<%@ Import NameSpace="System.Web.SessionState"%>
<%@ Import NameSpace="System.Web.UI"%>
<%@ Import NameSpace="System.Web.UI.HtmlControls"%>
<%@ Import NameSpace="System.Web.UI.WebControls"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>教务实验课系统</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<script language="C#" runat="server">
    public void checkUser(object sender, System.EventArgs e)
    { 
  string strType=null;
 
  strType=drpType.SelectedValue.ToString();
  SqlConnection conn;;
  SqlCommand comm=new SqlCommand();

 if(strType=="学生")
 {
  conn=new SqlConnection();
  conn.ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["DSN_student"];
  comm.CommandText="select * from student_login where s_id='"+ txtXh.Text.ToString()+" and sl_pwd='"+txtPwd.Text.ToString();
 }
else
{
   conn=new SqlConnection();
  conn.ConnectionString=System.Configuration.ConfigurationSettings.AppSettings["DSN_teacher"];
   comm.CommandText="select * from teacher_login where t_id='"+txtXh.Text.ToString()+" and tl_pwd='"+txtPwd.Text.ToString();
 }

try
{
conn.Open();
SqlDataReader dr=comm.ExecuteReader();
if(dr.Read())
{
//通过验证
if((Request.Cookies["userInfo"]==null))
{
HttpCookie cookie=new HttpCookie("userInfo");
cookie.Values.Add("userID",this.txtXh.Text.ToString());
cookie.Values.Add("userIdent",this.drpType.SelectedValue.ToString());
Response.AppendCookie(cookie);
}
else
{
HttpCookie cookie=new HttpCookie("userInfo");
cookie.Values.Add("userID",this.txtXh.Text.ToString());
cookie.Values.Add("userIdent",this.drpType.SelectedValue.ToString());
Response.AppendCookie(cookie); }
Server.Transfer("../student/index.aspx");
}
}
catch
{
//抛出异常
       lblErr.Text="与服务器连接失败!";
      } 
    finally
    { 
      conn.Close(); 
      conn=null; 
    } 
    }与数据库交互后总会出现"与服务器连接失败!",郁闷,想确认一下这里面代码到底有没有错,请高手指点一二!