Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:\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

like image 253
Deeptechtons Avatar asked Jun 14 '11 17:06

Deeptechtons


4 Answers

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

like image 195
Eben Roux Avatar answered Oct 07 '22 00:10

Eben Roux


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.

like image 35
abelenky Avatar answered Oct 06 '22 22:10

abelenky


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

like image 42
Yasmine GreenApple Avatar answered Oct 07 '22 00:10

Yasmine GreenApple


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.

like image 36
Chris Schiffhauer Avatar answered Oct 06 '22 23:10

Chris Schiffhauer