• Well, normally "DROP DATABASE" will also delete the physical files. In my case, I drop all tables first (which succeeds), then try to drop the database (which doesn't).

    The variation of the "ALTER DATABASE" command that was in this post, which is close to what I've seen floating around the web, didn't help. After using

    alter database MyDatabase SET SINGLE_USER WITH ROLLBACK IMMEDIATE

    it said

    ALTER DATABASE statement failed.

    Cannot open database "MyDatabase" requested by the login. The login failed.

    Login failed for user 'DOMAIN\myaccount'.

    when I tried to run the DROP DATABASE statement. And then, when using the one I found on this site:

    alter database MyDatabase SET OFFLINE WITH ROLLBACK IMMEDIATE

    It still says:

    Changes to the state or options of database 'MyDatabase' cannot be made at this time. The database is in single-user mode, and a user

    is currently connected to it.

    ALTER DATABASE statement failed.

    Cannot open database "MyDatabase" requested by the login. The login failed.

    Login failed for user 'DOMAIN\myaccount'.

    Is there a command to log yourself off of a database so it can be dropped? My account has all the privileges it needs - I'm a local Admin on the SQL box - and I'm the only one connected to the database - I know, since I'm doing testing and running a C# console app that connects & disconnects with the database as it finds and updates data. All of those SqlConnections are closed by the time I run this code to drop the database, however, which happens as part of the uninstall routine. I'd like it to programmatically drop/kill/delete the database, not have to manually restart SQL server and then have to manually delete it (which is where I'm at now, and have verified this works).

    Thanks,

    Tom