简体   繁体   中英

Login failure for user for an application in ASP.NET

I'm developing an application in asp.net and encountered the following problem:

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        string connString = "Data Source = JOHN-4E29FADEE; database=PEOPLE;";
        SqlConnection conn = new SqlConnection(connString);
        conn.Open();
        Response.Write("Succes");
        SqlCommand comanda = new SqlCommand();
        comanda.Connection = conn;
        comanda.CommandType = System.Data.CommandType.Text;
        comanda.CommandText = "Select PERSON_ID,FIRST_NAME,FATHER_INITIALS, LAST_NAME, BIRTHDATE,CNP,MOTHER_CNP,FATHER_CNP from PERSON order by FIRST_NAME"; 
        SqlDataReader dr = comanda.ExecuteReader();
        GridView4.DataSource = dr;
        GridView4.DataBind();
        conn.Close();
    }
    catch (SqlException exc)
    {
        Response.Write("Connection Error! " + exc.Message);
    }
}

When I launch the application I get Connection Error! Login failed for user Connection Error! Login failed for user .

您需要在连接字符串中提供sqlserver数据库的用户名和密码。

Try this :

connetionString="Data Source=ServerName;Initial Catalog=Databasename;
  User ID=UserName;Password=Password"

尝试SqlConnectionStringBuilder ...更容易为属性分配一些值,而不是从头开始创建一个神秘的连接字符串

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM