0

我在 asp.net 中开发一个应用程序,遇到了以下问题:

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

当我启动应用程序时,我得到Connection Error! Login failed for user.

4

3 回答 3

2

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

于 2013-10-31T14:11:20.897 回答
0

尝试 SqlConnectionStringBuilder ... 为属性分配一些值比从头创建一个神秘的连接字符串要容易得多

于 2013-10-31T14:20:53.557 回答
0

尝试这个 :

connetionString="Data Source=ServerName;Initial Catalog=Databasename;
  User ID=UserName;Password=Password"
于 2013-10-31T14:13:07.893 回答