using System;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.SqlServer;
using Microsoft.SqlServer.Server;
using System.Data;
using System.Data.SqlTypes;
using System.Data.Sql;
using System.Data.SqlClient;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection mySqlConnection = new SqlConnection();
mySqlConnection.ConnectionString = "Data Source=PC-201003241059;Initial Catalog=bs;Integrated Security=True";//"server = localhost; database = bs; integrated security=SSPI";
string SqlStr = "select * from uesrList where username = '" + username.Text + "' and pwd = '" + password.Text + "'";
SqlCommand SqlObj = new SqlCommand(SqlStr, mySqlConnection);
mySqlConnection.Open();
SqlDataReader Dr;
string Uid;
Dr = SqlObj.ExecuteReader();
if (Dr.Read())
{
Uid = Dr["id"].ToString();
System.Web.HttpContext.Current.Session["userid"] = Uid;
Session["name"] = Dr["username"].ToString();
Session["pwd"] = Dr["pwd"].ToString();
//System.Web.Security.FormsAuthentication.SetAuthCookie(Uid, true);
Dr.Close();
mySqlConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "info", "window.location = 'Default2.aspx';", true);
}
else
{
Dr.Close();
mySqlConnection.Close();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "info", "No!", true);
}
}
}
以上是的login的aspx.cs内容
前台是
用户名 username
密码 password
数据库为 manage表 id names password
运行报错
用户代码未处理sqlexception
无法打开登录 'bs' 中请求的数据库。登录失败。
用户 'PC-201003241059\Administrator' 登录失败。
求各位高人看下什么原因,谢谢