Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Well this i did the below to get the error, don't have a clue why the database connection fails.

  1. Create a new ASP.NET Website

  2. Add a new *.mdf database to App_Data

  3. Add some tables to it using Server Explorer in Visual Studio

  4. Right click DataBase and Copy Connection string. Insert it into WebConfig File like below

    <connectionStrings>
        <add name="DB" connectionString="Data Source=.SQLEXPRESS;AttachDbFilename=C:inetpubwwwrootgsApp_Datadb.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    
  5. Add some code to get the data from

    selectStatement = "select * from users";
    SqlDataAdapter da = new SqlDataAdapter(selectStatement,
    ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
    DataTable dtUsers = new DataTable();
    da.Fill(dtUsers);
    GridView1.DataSource = dtUsers.DefaultView;
    GridView1.DataBind();
    

and zoot you get the error

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
250 views
Welcome To Ask or Share your Answers For Others

1 Answer

I have a sneaky suspicion it has to do with permissions. Give full control to your "Authenticated Users".

In case you are wondering how to do this --- I am on Windows 7 and the steps go like this:

  • Right-click on the MDF file and click properties.
  • Select the "Security" tab and select your "Authenticated Users" (or something that looks right).
  • Click "Edit" and select the "Allow" check-box for "Full Control".
  • OK all the way out.

HTH


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...