如提例子
try
{
objConn = new SqlConnection(strConnection);
objConn.Open();
}
catch(SqlException ce)
{
throw new Exception("数据库连接错误:"+ce.Message.ToString()); 
}这样以后,怎么还会出现如下一大堆的错误信息,我想只出现“数据库连接错误:用户 'sa' 登录失败。 ”这一句,请问高手怎么办啊?系统错误信息:数据库连接错误:用户 'sa' 登录失败。 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Exception: 数据库连接错误:用户 'sa' 登录失败。源错误: 
行 24:  catch(SqlException ce)
行 25:  {
行 26:  throw new Exception("数据库连接错误:"+ce.Message.ToString()); 
行 27:  }
行 28:  }
 源文件: c:\inetpub\wwwroot\rong2soft\actiondll\cactiondb.cs    行: 26 堆栈跟踪: 
[Exception: 数据库连接错误:用户 'sa' 登录失败。]
   Rong2Soft.ActionDLL.cActionDB..ctor() in c:\inetpub\wwwroot\rong2soft\actiondll\cactiondb.cs:26
   Rong2Soft.WebForm1..ctor() in c:\inetpub\wwwroot\rong2soft\default.aspx.cs:33
   ASP.Default_aspx..ctor() in c:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\rong2soft\c00e56c3\c41d6367\zvrgrath.0.cs:0[TargetInvocationException: 调用的目标发生了异常。]
   System.RuntimeType.CreateInstanceImpl(Boolean publicOnly) +0
   System.Activator.CreateInstance(Type type, Boolean nonPublic) +66
   System.Activator.CreateInstance(Type type) +7
   System.Web.HttpRuntime.CreatePublicInstance(Type type)
   System.Web.UI.TemplateControlParser.GetCompiledInstance(String virtualPath, String inputFile, HttpContext context)[HttpException (0x80004005): 未能创建类型为“ASP.Default_aspx”的页。]
   System.Web.UI.TemplateControlParser.GetCompiledInstance(String virtualPath, String inputFile, HttpContext context)
   System.Web.UI.PageParser.GetCompiledPageInstanceInternal(String virtualPath, String inputFile, HttpContext context)
   System.Web.UI.PageHandlerFactory.GetHandler(HttpContext context, String requestType, String url, String path)
   System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, String path, String pathTranslated, Boolean useAppConfig)
   System.Web.MapHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 

解决方案 »

  1.   

    try
    {
    objConn = new SqlConnection(strConnection);
    objConn.Open();
    }
    catch(SqlException ce)
    {
    Response.Write("数据库连接错误:"+ ce.Message); 
    }
    这个Message就是简化了的错误
      

  2.   

    类里面不能使用Response.Redirect()怎么传到错误页面啊?
      

  3.   

    to  powerllr(笨笨的招财鸡) 
    类里面不能使用Response.Write()啊
      

  4.   

    把这个去掉 ce.Message.ToString() 不就没有一大堆了嘛
      

  5.   

    public class WithErr
    {
    System.Web.UI.Page withpage;
    public WithErr(System.Web.UI.Page withPage)
    {
    withpage=withPage;
    }
    public void OpenData()
    {
    try
    {
    objConn = new SqlConnection(strConnection);
    objConn.Open();
    }
    catch(SqlException ce)
    {
    withpage.Response.Write("<script language ='javascript'>alert('数据库连接错误:"+ce.Message.ToString+"')</script>");
    //throw new Exception("数据库连接错误:"+ce.Message.ToString()); 
    }
    }
    }
    调用:
    WithErr handerErr=new WithErr(this);
    handerErr.OpenData();也可以申明为静态的方法:public class WithErr
    {
    public WithErr()
    {
    }
    public static void OpenData(System.Web.UI.Page withPage)
    {
    try
    {
    objConn = new SqlConnection(strConnection);
    objConn.Open();
    }
    catch(SqlException ce)
    {
    withPage.Response.Write("<script language ='javascript'>alert('数据库连接错误:"+ce.Message.ToString+"')</script>");
    //throw new Exception("数据库连接错误:"+ce.Message.ToString()); 
    }
    }
    }
    调用:
    WithErr.OpenData(this);
      

  6.   

    按照CuiQingShaShou(摧情杀手) 的做法:错误信息如下:未将对象引用设置到对象的实例。 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 
    行 24:  catch(SqlException ce)
    行 25:  {
    行 26:  withpage.Response.Write("数据库连接错误"+ce.Message.ToString()); 
    行 27:  }
    行 28:  }
     
      

  7.   

    throw new Exception("数据库连接错误:"+ce.Message.ToString()); 改为:throw new Exception("数据库连接错误:"); 试一下
      

  8.   

    按照 ChengKing(bantamweight) 的方法
    错误如下:数据库连接错误: 
    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.Exception: 数据库连接错误:源错误: 
    行 24:  catch(SqlException ce)
    行 25:  {
    行 26:  throw new Exception("数据库连接错误:"); 
    行 27:  }
    行 28:  }
     
      

  9.   

    public class WithErr
    {
    System.Web.UI.Page withpage;
    public WithErr(System.Web.UI.Page withPage)
    {
    withpage=withPage;
    }
    public void OpenData()
    {
    try
    {
    objConn = new SqlConnection(strConnection);
    objConn.Open();
    }
    catch(SqlException ce)
    {
    withpage.Response.Write("<script language ='javascript'>alert('数据库连接错误:"+ce.Message.ToString+"')</script>");
    //throw new Exception("数据库连接错误:"+ce.Message.ToString()); 
    }
    }
    }
    调用:
    WithErr handerErr=new WithErr(this);
    handerErr.OpenData();也可以申明为静态的方法:public class WithErr
    {
    public WithErr()
    {
    }
    public static void OpenData(System.Web.UI.Page withPage)
    {
    try
    {
    objConn = new SqlConnection(strConnection);
    objConn.Open();
    }
    catch(SqlException ce)
    {
    withPage.Response.Write("<script language ='javascript'>alert('数据库连接错误:"+ce.Message.ToString+"')</script>");
    //throw new Exception("数据库连接错误:"+ce.Message.ToString()); 
    }
    }
    }
    调用:
    WithErr.OpenData(this);记得调用的时候参数一定是this(当前页面)
    如不行就去掉   ce.Message.ToString()  改为:withPage.Response.Write("<script language ='javascript'>alert('数据库连接错误:"')</script>");试试看