views:

21

answers:

1

Hi all, I am displaying the all the data in gridview from database table. I have attached the database file in app folder. But after writing the while i am running the application getting error like "Cannot open database requested in login 'Employee'. Login fails. Login failed for user 'HOME-47F64BE31D\Administrator'."

Here is all my code: aspx page:


aspx.cs: protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) GetData();

}
private void GetData()
{
    string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    SqlDataAdapter da = new SqlDataAdapter("GetEmp", str);
    da.SelectCommand.CommandType = CommandType.StoredProcedure;
    DataSet ds = new DataSet();
    da.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
}

Pls help me what is the error??

Thanks, Sumit

A: 

Your error is exactly what it's looks like: a database access error. That HOME-47F64BE31D\Administrator user doesn't have access to your database. You have two choices:

  • To grant access to that user into your database. You can define that permissions through your SQL Management Studio.
  • To inform a user with permission into your querystring; edit your configuration file to add a User ID=aaa;Password=bbb with a user with permissions

As side note, you shouldn't to use a sa user into your application.

Rubens Farias
Hi Mr. Rubens Farias,Thanks for your reply...But when i installed Database i didn't set any userid and password. I have systme account password..what to do pls reply..
sumit
lets to create a new user to you: can you log into your database through SQL Server Management Studio?
Rubens Farias
Hi i am not using SQL Server Management Studio, i am using SQL Server 2000 express edition...
sumit
At Object Explorer, expand Security/Logins, right click-it and select `new login...`; enter `sumit`, mark `SQL Authentication`, enter a password and select your application database as default; in your database, expand security/users and to add that `sumit` user and to make it db_datareader and db_datawriter role member
Rubens Farias