public SqlConnection Connect()
{
try
{
string Constr = @"server = (local);"+
"user id = sa;"+
"password = 9933;"+
"database = b2c;";
SqlConnection Conn  = new SqlConnection(Constr);
return Conn;
}
catch(SqlException ex)
{
   System.Web.HttpContext.Current.Session["messageerror"] = ex.Message;
   throw;
                            }                           return null;
}

解决方案 »

  1.   

    try
    {
    string Constr = @"server = (local);"+
    "user id = sa;"+
    "password = 9933;"+
    "database = b2c;";
    SqlConnection Conn  = new SqlConnection(Constr);
    return Conn;
    }
    catch(SqlException ex)
    {
    System.Web.HttpContext.Current.Session["messageerror"] = ex.Message;
    throw;
    }
      

  2.   

    to saucer(思归)大哥:
    还是不行,我运行了。他并没有catch(SqlException ex)
    {
       System.Web.HttpContext.Current.Session["messageerror"] = ex.Message;
       throw;
                                }
    做到这一步以后打开MessageError.aspx(我做的显示错误)页面。而是一直往下运行。由于后面的代码中得到的conn是返回为null,所以,错误总是出现在下面的代码。。
      

  3.   

    把return null 放进catch里面,试试.
      

  4.   

    把return null 放进catch里面,试试.
      

  5.   

    may be you can try:
    try
    {
    ...
    return a;
    }
    catch
    {
    ...
    }
    finally
    {
    return ...
    }
      

  6.   

    控制不能离开 finally 子句主体
      

  7.   

    确保Connect()中只有一个Return