2009-07-06 2 views
0

Пока я пытаюсь войти в приложение, я получаю эту ошибку «Не удается открыть базу данных, запрошенную в логине« 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();  

    } 
+0

Не могли бы вы переформатировать свой код, который сейчас трудно читать. –

+0

Является ли ваша база данных SQL Server Express? –

ответ

-1

Убедитесь, что SQL excepts сервер соединения через TCP/IP, пытаясь войти на сервер с помощью студии управления SQL сервера с использованием TCP/IP (Свойства подключения -> Сеть Protocoll) если это не работает, откройте TCP/IP для этого экземпляра.

+0

В этом случае соединение не будет полностью выполнено. В сообщении об ошибке указано, что логин не удался, поэтому это проблема безопасности. –

Смежные вопросы