用户代码未处理sqlexception的问题

来源:百度知道 编辑:UC知道 时间:2024/05/26 22:56:10
点登陆就出现

用户代码未处理SqlException的问题!

而又提示:用户 'sa' 登录失败。原因: 未与信任 SQL Server 连接相关联
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class index : System.Web.UI.Page
{

protected void Page_Load(object sender, EventArgs e)
{
if (Session["uid"] == null)
{
T2.Visible = false;

}
else
{
T1.Visible = false;

}
if (!Page.IsPostBack)
{

}
}
protected void Button1_Click(object sender, EventArgs

SqlConnection conn = DB.getConnection();
这句代码应该得到一个已经设置了ConnectionString的Connection对象
错误应该是DB.getConnection()返回的Connection对象的连接字符串有问题
所以你在conn.Open()抛出异常 然后你没有对异常进行处理
而且没有设置ASP.Net异常模式
所以异常显示到了客户端浏览器上
检查DB.getConnection(); 方法设置的连接字符串是否正确