Removing orphaned mdf and ldf files ?

  • I have orphaned mdf and ldf files i would like to delete, but whenever i use the delete function, i get an access denied, even though i am logged in as server admin.

    I have tried recreating the database to point to those files, but it wont let me.

    It also will not let me rename the files.

    When i try to do a detach or sp_helpfile, it errors, due to not finding the database name.

    Any ideas

    Thanks

  • if you can't delete them they probably are not orphaned.

    [font="Comic Sans MS"]The GrumpyOldDBA[/font]
    www.grumpyolddba.co.uk
    http://sqlblogcasts.com/blogs/grumpyolddba/

  • So how do i delete them ?

  • Check the permissions on the file. Sometimes when you detach a database file, it looses all permissions. No idea why. Take ownership and then add permissions for the administrators back.

    If it's not permissions on the file, then getting an access denied means that the files are in use by SQL, which means they are not orphaned database files, which means if you want to delete you'll have to drop the database from within SQL.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Please run this command and post the result, I think I have the same problem here...

    select * from sysfiles

    select * from sys.sysaltfiles where [dbid] = 'your db id'

    Regards

    Edu

  • I took back ownership and the delete worked fine!

    Thanks 🙂

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

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