请帮帮我,我正在尝试使用ASP.net中的C#创建登录页面。 我在笔记本电脑上安装了SQL Server Management Studio,并且在运行*“ login.aspx.cs”代码时出现以下错误:
与网络相关或特定于实例的错误发生在 建立与SQL Server的连接。找不到服务器或 无法访问。验证实例名称正确,并且 SQL Server配置为允许远程连接。 (提供者:SQL 网络接口,错误:26 -连接字符串无效)
以下错误发生在行- da.Fill(ds)在此特定行中出了什么问题?
数据库名称-tempdb表名称-UserLoginData
受保护的无效btnlogin_Click(对象发送者,EventArgs e)
{
String mycon = "Data Source=(local)\\MSSQLSERVER;Initial Catalog=tempdb;Integrated Security=True";
SqlConnection scon = new SqlConnection(mycon);
String myquery = "select * from UserLogindata where username='" + txtUserName.Text + "'";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = myquery;
cmd.Connection = scon;
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
String uname;
String pass;
String status;
if (ds.Tables[0].Rows.Count > 0)
{
uname = ds.Tables[0].Rows[0]["username"].ToString();
pass = ds.Tables[0].Rows[0]["password"].ToString();
status = ds.Tables[0].Rows[0]["status"].ToString();
scon.Close();
if (status == "Open")
{
if (uname == txtUserName.Text && pass == txtPassword.Text)
{
Session["username"] = uname;
Response.Redirect("Dashboarddd.aspx");
}
else
{
Label199.Text = "Invalid Username or Password - Relogin with Correct Username Password- No. of Attemps Remaining : " + (2 - attemptcount);
attemptcount = attemptcount + 1;
}
}
else
{
Label199.Text = "Your Account Locked Already : Contact Administrator";
}
}
else
{
Label199.Text = "Invalid Username or Password - Relogin with Correct Username Password ";
}
if (attemptcount == 3)
{
Label3.Text = "Your Account Has Been Locked Due to Three Invalid Attempts - Contact Administrator";
setlockstatus(txtUserName.Text);
attemptcount = 0;
}
}
private void setlockstatus(String username1)
{
String mycon = "Data Source=(local)\\MSSQLSERVER; Initial Catalog=tempdb; Integrated Security=True";
String updatedata = "Update UserLoginData set status='Locked' where username='" + username1 + "'";
SqlConnection con = new SqlConnection(mycon);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = updatedata;
cmd.Connection = con;
cmd.ExecuteNonQuery();
}