帮助数据库连接

时间:2009-07-06 09:46:01

标签: database configuration

当我尝试登录应用程序时,我收到此错误“无法打开登录'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 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();     

    }

2 个答案:

答案 0 :(得分:1)

您是否有登录权限?密码是否正确?

答案 1 :(得分:-1)

通过使用tcp / ip(连接属性 - >网络协议1)尝试使用sql server management studio登录服务器,确保sql server通过tcp / ip排除连接,如果这不起作用则打开提供此实例的TCP / IP。