none
Unable to open the physical file (MDF). Operating system error 32 (error not found)

    Question

  • I am trying to run a WinForms application that was originally written against a SQL Express 2005 database, but I have SQL Express 2008 installed on my pc. When I debug the app in Visual Studio I get the following error:
    System.Data.SqlClient.SqlException was unhandled Message="Unable to open the physical file \"C:\\OTJ\\DBFile\\OTJDB.mdf\". 
    Operating system error 32: \"32(error not found)\".
    An attempt to attach an auto-named database for file C:\\OTJ\\DBFile\\OTJDB.mdf failed.
    A database with the same name exists, or specified file cannot be opened, or it is located on UNC share."
    and if I try to attach the file in SSMS 2008

     

    CREATE FILE encountered operating system error 32(error not found) while attempting to open or create the physical file 
    'C:\OTJ\DBFile\OTJDB.mdf'. (Microsoft SQL Server, Error: 5123)
    I have given 'everyone' full access to the .mdf and .ldf files (NTFS permissions), that doesn't help.

     

    When the application starts up it first checks that the database exists and if it does then it checks the version (stored in a config table) runs any required update SQL scripts then continues. What is odd is that some data seems to be returned as there are some values shown in the application that can only come from the database. But then I don't get why I'm getting the errors above.

     

    I can connect to it in Visual Studio, expand the tables, stored procedures etc. I can edit and execute the stored procedures too. The connection in Visual Studio is:

     

    Data Source=.;AttachDbFilename=|DataDirectory|\OTJDB.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True
    
    Any ideas?
    • Edited by Simon Martin Sunday, November 08, 2009 3:33 PM Weird markup appeared
    Sunday, November 08, 2009 3:32 PM

Answers

  • Hi,

    It seems you connect to a SQL Server 2005 instance in SQL Server 2008 Management Studio. If  you have installed SQL Server Express 2008, please make sure the SQL Server Express 2008 instance name and connect to it in SQL Server 2008 Management Studio. Try the following steps:
    1. On the Start menu, point to All Programs, point to Microsoft SQL Server 2008, point to Configuration Tools, and then click SQL Server Configuration Manager.
    2. In SQL Server Configuration Manager, in the left pane, click SQL Server Services.
    3. In the details pane, right-click each SQL Server, and then click Properties.
    4. Go to Advanced tab, check the file version that should be 2007.100.xxxx.x.
    5. Click OK to close SQL Server Configuration Manager.
    6. In SQL Server 2008 Management Studio, connect to the correct server name for SQL Server 2008 instance.

    If there are any more questions, please let me know.
    Thanks.


    ***Xiao Min Tan***Microsoft Online Community***
    • Marked as answer by Simon Martin Monday, November 16, 2009 11:53 AM
    Monday, November 16, 2009 2:55 AM

All replies

  • Hi,

    The errors might be caused by:
    1. Make sure that the data file is available at the location pointed to by the connection string. For a relative path, when you run the application, |DataDirectory| will point to the location of your application executable. When you debug the program, this is usually ...\projectfolder\bin\debug. Please check the data file is available there.
    2.. If you set User Instance=true in the connection string, a user instance is generated at the first time. Then, the master and msdb system databases are copied from the Template Data folder to a path under the user's local application data repository directory for exclusive use by the user instance. This path is typically C:\Documents and Settings\<UserName>\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS. When a user instance starts up, the tempdb, log, and trace files are also written to this directory. A name is generated for the instance, which is guaranteed to be unique for each user. Please check the C:\Documents and Settings\<UserName>\Local Settings\Application Data\Microsoft\Microsoft SQL Server Data\SQLEXPRESS directory and delete it. This location is for Windows Server 2003.The location for vista is C:\users\<username>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS.
    3. The user instance cannot attach the database because the user does not have the required permissions. The user instance executes in the context of the user who opened the connection—not the normal SQL Server service account. The user who opened the user instance connection must have write permissions on the .mdf and .ldf files that are specified in the AttachDbFilename option of the connection string.


    If there are any more questions, please let me know.
    Thanks.
    ***Xiao Min Tan***Microsoft Online Community***
    Tuesday, November 10, 2009 7:32 AM
  • Hi,

    Thanks for your help. I need to do some more research into user instances I think - I didn't know about the detail in point2.

    I deleted the C:\users\<username>\AppData\Local\Microsoft\Microsoft SQL Server Data\SQLEXPRESS folder and it was recreated the next time I tried to debug the application, but didn't fix the problem. However it did let me discover that part of the problem was that there were 2 connection strings and it was the second that was failing with the error thrown. Fixing that I can now debug my application from Visual Studio ok and the application runs normally. I did follow the links in the error - but don't think they solve the problem.

    However it led me onto a further problem; I tried to attach the database to my SQLExpress in SSMS (I like using SSMS for SQL more than Visual Studio) but it now throws a new error (detail below). If I'm reading this correctly it says that SQL Express 2008 cannot open my file because it is too new? Previously I was using SQL Express 2005 so I don't know how I could have created a version that's newer than the SQL Express 2008?

    Any idea?

    TITLE: Microsoft SQL Server Management Studio
    ------------------------------
    
    Attach database failed for Server 'SIMON\SQLEXPRESS'.  (Microsoft.SqlServer.Smo)
    
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&ProdVer=10.0.2531.0+((Katmai_PCU_Main).090329-1045+)&EvtSrc=Microsoft.SqlServer.Management.Smo.ExceptionTemplates.FailedOperationExceptionText&EvtID=Attach+database+Server&LinkId=20476
    
    ------------------------------
    ADDITIONAL INFORMATION:
    
    An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
    
    ------------------------------
    
    The database 'C:\OTJ\DBFILE\OTJDB.MDF' cannot be opened because it is version 655. This server supports version 612 and earlier. A downgrade path is not supported.
    Could not open new database 'C:\OTJ\DBFILE\OTJDB.MDF'. CREATE DATABASE is aborted. (Microsoft SQL Server, Error: 948)
    
    For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=948&LinkId=20476
    

    • Edited by Simon Martin Tuesday, November 10, 2009 4:33 PM additional detail about the error message
    Tuesday, November 10, 2009 4:30 PM
  • Hi,

    Based on the error message, it says you attached a SQL Server 2008 database to an instance of SQL Server 2005. Therefore, you need to make sure the version of SQL Server instance that you want to attach the database to. Please execute the following statement in SQL Server Management Studio to check the SQL Server version:
    Select @@version

    If there are any more questions, please let me know.
    Thanks.
    ***Xiao Min Tan***Microsoft Online Community***
    Wednesday, November 11, 2009 10:03 AM
  • Er... that's really odd. Running that command gives me the following:
    Microsoft SQL Server 2005 - 9.00.4053.00 (Intel X86)   May 26 2009 14:24:20   Copyright (c) 1988-2005 Microsoft Corporation  Express Edition on Windows NT 6.1 (Build 7600: )

    Which says it is SQL Server 2005 - but I'm in SQL Server 2008 SSMS - I don't get it. I installed SQL Express 2008, the splash screen is 2008 so why is it saying its 2005???????

    Microsoft SQL Server Management Studio                        10.0.2531.0
    Microsoft Data Access Components (MDAC)                        6.1.7600.16385
    Microsoft MSXML                        3.0 5.0 6.0
    Microsoft Internet Explorer                        8.0.7600.16385
    Microsoft .NET Framework                        2.0.50727.4927
    Operating System                        6.1.7600
    Server Version: 9.0.4053
    • Edited by Simon Martin Thursday, November 12, 2009 5:40 PM added server version from properties
    Thursday, November 12, 2009 5:39 PM
  • Hi,

    It seems you connect to a SQL Server 2005 instance in SQL Server 2008 Management Studio. If  you have installed SQL Server Express 2008, please make sure the SQL Server Express 2008 instance name and connect to it in SQL Server 2008 Management Studio. Try the following steps:
    1. On the Start menu, point to All Programs, point to Microsoft SQL Server 2008, point to Configuration Tools, and then click SQL Server Configuration Manager.
    2. In SQL Server Configuration Manager, in the left pane, click SQL Server Services.
    3. In the details pane, right-click each SQL Server, and then click Properties.
    4. Go to Advanced tab, check the file version that should be 2007.100.xxxx.x.
    5. Click OK to close SQL Server Configuration Manager.
    6. In SQL Server 2008 Management Studio, connect to the correct server name for SQL Server 2008 instance.

    If there are any more questions, please let me know.
    Thanks.


    ***Xiao Min Tan***Microsoft Online Community***
    • Marked as answer by Simon Martin Monday, November 16, 2009 11:53 AM
    Monday, November 16, 2009 2:55 AM
  • Hi, Thanks for the help.
    Somehow it seems my SQLExpress instance is 2005, whereas MSSQLSERVER is 2008. I guess SQL Express was installed when I installed Visual Studio 2008.

    I don't particularly want SQL Server installed on my workstation; I only need SQL Express, so I think the cleanest thing for me to do is to uninstall both versions and re-install SQL Express 2008.

    Mnay thanks for your help :)

    Simon
    Monday, November 16, 2009 11:53 AM
  • System Error 32:'The process cannot open the file…'
    You may experience an error similar to Unable to open the physical file "......\Simple.mdf". Operating System error 32:"The Process cannot access the file because it is being used by another process". There is an annoying problem with using Microsoft SQL Server Management Studio Express to create the database as we did in that the database is attached to Management Studio Express and we can't also attach it in VWD.

    To fix this, open Management Studio Express, expand Databases and right-click the SimpleCMS database. Choose Tasks | Detach and the database will be detached from Management Studio Express. You can then follow the steps above to open the SimpleCMS database in Visual Web Developer without the error

    Friday, November 20, 2009 12:06 AM
  • HI
    I AM DOUBT IN SOME ERROR
    Error 1 Unable to copy file "Application\Data\kamakshi.mdf" to "bin\Debug\Data\kamakshi.mdf". Access to the path 'Application\Data\kamakshi.mdf' is denied.
    WHY I GOT THIS ERROR?
    I DONT KNOW
    CAN U HELP ME!!!!!!!!!!
    AT THE SAME ERROR FOR LOG.LDF FILE ALSO
    Monday, January 11, 2010 3:28 PM
  • Hi all, im getting a similar error and so far none of the Google / Forums have come up with the right answer. Any help would be of a great help.

    Error message is as follows (copied from dialog box):

    ---------------------------
    Microsoft Visual C# 2010 Express
    ---------------------------
    Unable to open the physical file "C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\scratch.mdf". Operating system error 32: "32(failed to retrieve text for this error. Reason: 1815)".

    An attempt to attach an auto-named database for file C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA\scratch.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.
    ---------------------------
    OK  
    ---------------------------

    As you can see im running Visual C# express 2010, plus 'SQL Server 2008 R2'. I am literally starting a new 'webApplication1' form in VC# and trying to 'Add New Data Source' and when I try to 'Add New Connection' to an SQL Server (.mdf) I get the error msg as above. The folder 'Scratch' exists in my database (as I can see from SQL Server Management Studio) so Im at a loss to why I cant connect to it.

    I've tried various ideas like checking not got two database instances, every server option is running, also the post marked answer above gives my version number as 2009.1....

    I did manage to get a connection yesterday when I first installed SQL server and VWD 2010, but since I have shut down and restarted my pc today I havent managed to get this to work and im in my 5th hour of trying out ideas!

    Cheers

    Trev.

    Thursday, August 19, 2010 1:49 PM
  • found my answer here...

    http://social.msdn.microsoft.com/Forums/en-US/sqlnetfx/thread/e8877bf9-8cde-42e3-ace1-dded04b90b56

     

    looks like stopping the server may clear out any instances running that prevent it from running again.

    Thursday, August 19, 2010 2:04 PM