Subversion Repositories Aluchemie.datataker

Rev

Blame | Last modification | View Log | Download

 Cannot alter the user 'dbo'. (Microsoft SQL Server, Error: 15150)

Some times we may get the below error while updating the login from dbo to some other login from user mapping window.

1. I have database which is mapped with dbo login and dbo schema.
2. I tried to update the database with app_user login, then it displays that error message.

To fix the issue we need to change the default owner to 'sa' and then tried to update the login.

Use database_name
exec sp_changedbowner 'sa'

It may cause because dbo is mapped with some other login, then we need to change the dbo login name to 'sa', it is because the sa login is reffered as dbo and it will exists in all the databases. So we should not modify the dbo login to any other login except 'sa'.


Msg 3702, Level 16, State 3, Line 1
Cannot drop database “MyDBName” because it is currently in use.

The reason was very simple as my database was in use by another session or window. I had option that I should go and find open session and close it right away; later followed by dropping the database. As I was in rush I quickly wrote down following code and I was able to successfully drop the database.

USE MASTER
GO
ALTER DATABASE MyDBName
SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DROP DATABASE MyDBName
GO