Пока я пытаюсь войти в приложение, я получаю эту ошибку «Не удается открыть базу данных, запрошенную в логине« HealthCare ». Ошибка входа. Ошибка входа для пользователя« HOME-7A082AE66C \ Sumit ». Вот мой код:Помощь с подключением к базе данных
protected void Button1_Click(object sender, System.EventArgs e)
{
//string uid = TextBox1.Text.Trim();
//string Password = TextBox2.Text.Trim();
con = new SqlConnection("server=localhost;uid=;password=;Database=HealthCare;trusted_Connection=true");
switch(RadioButtonList1.SelectedIndex)
{
case 0:
cmd=new SqlCommand("select * from login where [email protected] and [email protected]",con);
cmd.Parameters.Add(new SqlParameter("@Uid",SqlDbType.VarChar,10));
cmd.Parameters.Add(new SqlParameter("@Password",SqlDbType.VarChar,20));
cmd.Parameters["@Uid"].Value=TextBox1.Text;
cmd.Parameters["@Password"].Value=TextBox2.Text;
con.Open();
dr=cmd.ExecuteReader();
if(dr.Read())
{
Response.Redirect("http://localhost/eHealthCare/registration.aspx");
}
else
Response.Redirect("http://localhost/eHealthCare/errormessage.aspx");
dr.Close();
con.Close();
break;
case 1:
cmd=new SqlCommand("select * from login where [email protected] and [email protected]",con);
cmd.Parameters.Add(new SqlParameter("@Uid",SqlDbType.VarChar,10));
cmd.Parameters.Add(new SqlParameter("@Password",SqlDbType.VarChar,20));
cmd.Parameters["@Uid"].Value=TextBox1.Text;
cmd.Parameters["@Password"].Value=TextBox2.Text;
con.Open();
dr=cmd.ExecuteReader();
if(dr.Read())
{
Response.Redirect("http://localhost/eHealthCare/doctordatabase.aspx");
}
else
Response.Redirect("http://localhost/eHealthCare/errormessage.aspx");
dr.Close();
con.Close();
break;
case 2:
cmd=new SqlCommand("select * from login where [email protected] and [email protected]",con);
cmd.Parameters.Add(new SqlParameter("@Uid",SqlDbType.VarChar,10));
cmd.Parameters.Add(new SqlParameter("@Password",SqlDbType.VarChar,20));
cmd.Parameters["@Uid"].Value=TextBox1.Text;
cmd.Parameters["@Password"].Value=TextBox2.Text;
con.Open();
dr=cmd.ExecuteReader();
if(dr.Read())
{
Response.Redirect("http://localhost/eHealthCare/diagnosis.aspx");
}
else
Response.Redirect("http://localhost/eHealthCare/http://localhost/eHealthCare/errormessage.aspx");
dr.Close();
con.Close();
break;
default:
break;
}
con.Close();
}
Не могли бы вы переформатировать свой код, который сейчас трудно читать. –
Является ли ваша база данных SQL Server Express? –