Strange File issue > "CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file"

  • Recently I have had to move and restructure my SQL farms and environment. I had detached a SolarWinds database called NetPerfMon that consisted of three data (mdf) files and one log(ldf) file. The database detached without issue.

    Today one of my engineers needed to retrieve some data and when I went to restore it I found the files still there. That's great I thought. Just re-attach. Then I received this error:

    "CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'd:\userdbs\pathToFile.mdf'"

    I listed the files and database names from sys.databases and this database is DEFINITELY not loaded in to SQL. When I looked at all the open file handles with Sysinternals "Handle.exe", it lists the netperfmon mdf files as being open by the SQL server process.

    This server has been rebooted several times during the move since I dropped the original database. Why (WHY!?!?) would SQL still have these files open?

    I already worked around the issue by restoring it somewhere else but I'm dying of curiosity....why would SQL have these files open when the database is not currently attached to the system and hasn't been for several starts? Also why when attaching to an EXISTING file would it be trying to create the data file as it indicates in the error?

  • The restore executing user doesn't have permissions on that folder. I had the same issue earlier when I attempted to backup a database to the F: drive. Copy the files to %SQL_HOME%\Backup and try to do it again, it should work then.

    Edit: It's either a problem reading the file or the location you're specifying the new data files to go (by the fact it says "create").

    Try a restore verifyonly on the datafile to identify which part of the restore you're having problems with (if the verifyonly is successful then it's the creation location).


    Dird

  • I had detached a SolarWinds database called NetPerfMon that consisted of three data (mdf) files and one log(ldf) file.

    That might be the problem. Detaching a db in SQL 2005 and later versions changes the permissions on the file. So it might be a permissions issue trying to read the existing files.

    For that reason and others, I suggest using "SET OFFLINE" instead of detaching whenever you can.

    SQL DBA,SQL Server MVP(07, 08, 09) A socialist is someone who will give you the shirt off *someone else's* back.

  • Sorry for the late reply. Been in the middle of a data center move and well...you know how that can be.

    Thank you for your responses. I think you kinda missed my question though. I'm not really interested in why SQL couldn't attach to the files. I worked around that like I said. What my question is is was this:

    "When I looked at all the open file handles with Sysinternals "Handle.exe", it lists the netperfmon mdf files as being open by the SQL server process.

    This server has been rebooted several times during the move since I dropped the original database. Why (WHY!?!?) would SQL still have these files open? "

    What I am trying to say there is that SQL doesn't show the db as attached/loaded and its not listed in sys.databases however the OS is telling me that the SQL process has the files open. So why would the SQL process have handles to these files if it is not using them? Even after two reboots.

    Thanks again....

  • kenneth.gore (8/18/2013)


    So why would the SQL process have handles to these files if it is not using them? Even after two reboots.

    Can't think of any logical reason if they're not registered with the instance.

    Are you sure they're not part of a different DB than you're expecting? Do they appear anywhere in this output:

    SELECT physical_name, DB_NAME(database_id) Database_Name FROM sys.master_files

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply