Error 5123

  • I'm getting Error 5123 "Cannot open because file is being used by another process" when I try re-attaching a database (.mdf) I just detached. 

    I'm afraid I issued a DBCC command (which may be locking the file) right before I detached the DB.  DBCC OPENTRAN (oldoaiapp)

    Does anyone know how I can identify and kill whatever process is attached to my .mdf database?  I obviously cannot use Query Analyzer as I cannot see the database anymore.

    Thanks,

    Leslie

  • You can use something like Process Explorer from SysInternals to see what process has it open. It may not be SQL Server, after all.

    SysInternals Web Site

    K. Brian Kelley
    @kbriankelley

  • I did have cases like that when restarting SQL Server 6.5 (long ago)

    The reason was if I remember correctly an anti-virus SW and someone made a suggestion that it was a backup SW. Anyway, once the file was released by SQL Server the other SW was able to access it, so SQL Server had an error that the database file was used by another process

    Yelena

     

    Regards,Yelena Varsha

  • Yelena,

    I did find that it was indeed SQL Server that has the lock on the .mdf

    I had issued the DBCC OpenTran (<dbname&gt, then detached the DB.  Well the DBCC OpenTran() command wants you to run a Backup afterwards, so I'm sure that is what caused the lock.  It'd have been nice of SQL had warned me that there was a lock on the DB and wouldn't have let me detach the DB.

    In any case, we tried a reboot and that didn't release the .mdf  So tonight we are going to stop SQL Server, move the .mdf/.ldf files, then restart SQL Server (hopefully w/o a problem).  Then hopefully we'll be able to reattach the DB.

    So, in essence you were right on the money for the cause.  Now it's really the solution I'm after!

    Cheers,

    Leslie

  • Use QA (Doesn't need access to userdb) and  sp_who to find the SPID for the relevant process.

    Then use the kill command to release it.  

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

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