SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Strange File issue > "CREATE FILE encountered operating system error 5(Access is denied.) while...


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

Author
Message
kenneth.gore
kenneth.gore
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 93
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?
Dird
Dird
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1177 Visits: 821
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
ScottPletcher
ScottPletcher
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18772 Visits: 7402
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) Prosecutor James Blackburn, in closing argument in the Fatal Vision murders trial:
If in the future, you should cry a tear, cry one for them [the murder victims]. If in the future, you should say a prayer, say one for them. And if in the future, you should light a candle, light one for them.
kenneth.gore
kenneth.gore
Valued Member
Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)Valued Member (63 reputation)

Group: General Forum Members
Points: 63 Visits: 93
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....
HowardW
HowardW
SSCertifiable
SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)SSCertifiable (5.9K reputation)

Group: General Forum Members
Points: 5935 Visits: 9892
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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search