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.
- 开发者_C百科
Create a new ASP.NET Website
Add a new *.mdf database to App_Data
Add some tables to it using Server Explorer in Visual Studio
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>
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
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
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.
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
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.
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:
- SSMS have attached data.mdf
- 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
精彩评论