c#连接SqlServer数据库失败!!代码如下,总是显示数据库连接失败,到底是什么问题 10
protectedvoidPage_Load(objectsender,EventArgse){try{stringconn="DataSource=.;InitialC...
protected void Page_Load(object sender, EventArgs e)
{
try
{
string conn = "Data Source=.;Initial Catalog=hamsum;User ID=zgl;Pwd=123456";
SqlConnection con = new SqlConnection(conn);
string username = Request.Form["username"].ToString();
string pwd = Request.Form["password"].ToString();
try
{
con.Open();
logindao userlogin = new logindao();
if (userlogin.login(con, username, pwd))
{
Response.Redirect("submitnews.aspx");
}
else
{
Response.Write("<script>alert('账号或密码错误!')</script>");
}
}
catch (System.Exception)
{
Response.Write("<script>alert('数据库连接失败!')</script>");
}
finally
{
try
{
con.Close();
}
catch (System.Exception)
{
throw;
};
}
}catch(Exception){
return;
}
} 展开
{
try
{
string conn = "Data Source=.;Initial Catalog=hamsum;User ID=zgl;Pwd=123456";
SqlConnection con = new SqlConnection(conn);
string username = Request.Form["username"].ToString();
string pwd = Request.Form["password"].ToString();
try
{
con.Open();
logindao userlogin = new logindao();
if (userlogin.login(con, username, pwd))
{
Response.Redirect("submitnews.aspx");
}
else
{
Response.Write("<script>alert('账号或密码错误!')</script>");
}
}
catch (System.Exception)
{
Response.Write("<script>alert('数据库连接失败!')</script>");
}
finally
{
try
{
con.Close();
}
catch (System.Exception)
{
throw;
};
}
}catch(Exception){
return;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询