views:

69

answers:

2

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();     

 }
A: 

Make sure that sql server excepts connections over tcp/ip by trying to log in on to the server using sql server management studio using tcp/ip (Connection Properties--> Network protocoll) if that doesn't work then open up the TCP/IP for this instance.

Mischa Kroon
In that case the connection would fail altogether. The error message says that the login failed, so it's some kind of security issue.
Philippe Leybaert
A: 

Do you have login access? and is the password correct?

waqasahmed