开发者

Getting Error while read the data from table

I am displaying all the data in a gridview from database table. I have attached the database file in app folder. But while I am running the application I'm 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:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField="FirstName" HeaderText="FirstName" />
    <asp:BoundField DataField="LastName" HeaderText="L开发者_高级运维astName" />
    <asp:BoundField DataField="HireDate" HeaderText="HireDate" />      
    </Columns>        
</asp:GridView>    
<asp:label ID="lblStatus" runat="server"></asp:label>

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

Please help me. What is the error?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜