Dropping database programatically.

  • Dear All,

    I have a database mounted in my system. My application has to check whether there is any existing database and if exists it has to be dropped in order to recreate the same while installing.

    For this I have used the below:

    USE MASTER

    GO

    DROP DATABASE MyTestDatabase

    When I try to drop the database it is giving the below error:

    Cannot drop the database 'foo' because it is currently in use.

    Can any one tell me how to get rid of the same?

    [font="Arial"]Nothing is impossible with Hard Work[/font]:)

  • Try this. You can set it to single user mode and immediately roll back all of the transactions. Then it should be all yours...

    Alter Database MyDatabase Set SINGLE_USER With Rollback Immediate

    Drop Database MyDatabase

  • Dear Ken,

    Thanks a lot for your timely help.

    It was working when, I am altering the database as you said and then using the master database, then I issued the drop command.

    🙂

    [font="Arial"]Nothing is impossible with Hard Work[/font]:)

Viewing 3 posts - 1 through 2 (of 2 total)

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