Unable to open the physical file Operating system error 32

会有一股神秘感。 提交于 2019-12-17 19:23:17

问题


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:\inetpub\wwwroot\gs\App_Data\db.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


回答1:


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




回答2:


The top result from Google seems to address your question:

Just in case if anybody is still looking for solution to this error, this works for me:

1) Open the VStudio project for which you need to connect to a SQL database

2)Separately, Go to Start->Run->Services.msc

3) Look for SQL Server (SQLEXPRESS) service and Stop it

4) Start it again

5) Try connecting your database now.

Looks like the reason it works has something to do with User Instance discussion that is going on in this thread.




回答3:


I was struggling with this error to and I found that the error was in the database instance that was online so I took it offline from SQLserver management studio,I've shared the steps followed and the solution HERE




回答4:


In my case, I had the database in instance MSSQLSERVER while trying to attach it to SQLEXPRESS. Dropping from the first instance freed the file.




回答5:


About error: Operating system error 32, Open error ...

First off all, give permission to mdf file. In my case NETWORK SERVICE account have FULL ACCESS on data.mdf.

Well, my workspace:

  1. SSMS have attached data.mdf
  2. In same time in VS2010 I have open solution with same database file: data.mdf, but can not make successfully connection.

Solution: in CONNECTION PROPERTIES on USER INSTANCE change TRUE to FALSE and refresh connection inside VS on this database. Finaly, no more opening error and you have access on same database file in same time from SSMS and VS2010.

Connection string example:

DataSource=.\SQLEXPRESS;AttachDbFilename=D:\Contracts\App_Data\data.mdf;Integrated Security=True;User Instance=False

Regards

Dražen-ZG



来源:https://stackoverflow.com/questions/6347312/unable-to-open-the-physical-file-operating-system-error-32

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!