Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
259 views
in Technique[技术] by (71.8m points)

c# - Unable to open the physical file Operating system error 32

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...