Hi all, While i am trying login to the application i am getting this error "Cannot open database requested in login 'HealthCare'. Login fails. Login failed for user 'HOME-7A082AE66C\Sumit'." Here is my code:
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 Userid=@Uid and Password=@Password",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 Userid=@Uid and Password=@Password",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 Userid=@Uid and Password=@Password",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();
}