This entry was posted on Monday, May 23rd, 2005 at 11:48 am and is filed under General, Tech data. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.
I have a dream, A dream where all databases have the same database owner, and all password user set up the same. I dream of a day when the hertic database thinking their are creation Administrator or the the Non believer that thing they have No owner all see the light and and come to the true database owner, Praise the almighty `sa` for under `sa` noone is shut out by a badly set up password user. `sa` Love everyone all are welcome, as long as they are favour with the great Ron.
So I have created a script to convert the nonbelieves to the cause.
USE [database name]
Execute sp_changedbowner @loginame = `sa`
Execute sp_dropuser password
Execute sp_addlogin password
Execute sp_adduser password
Execute sp_change_users_login @Action = Update_One,
@UserNamePattern = password,
@LoginName = password;
Execute sp_addrolemember @rolename = db_datareader, @membername = password
Execute sp_addrolemember @rolename = db_datawriter, @membername = password
Here is the breakdown of what the script does:
USE [database Name]
This connect to the apporiate database
Execute sp_changedbowner @loginame = `sa`
this command changes the database owner over to sa [system administrator]
Execute sp_dropuser password
This line drop the password
Execute sp_addlogin password
This line add the password login
Execute sp_adduser password
This line add the password user
Execute sp_change_users_login @Action = Update_One,
@UserNamePattern = password,
@LoginName = password;
This crazy looking script make sure that the user password is linked to the login password
Execute sp_addrolemember @rolename = db_datareader, @membername = password
Execute sp_addrolemember @rolename = db_datawriter, @membername = password
These two lines grant the roles db_datareader and db_datawriter to the sp_addrolemember.
The script will throw out a lot of errors, by like any force religious conversion it was always going to be messy. It very rarely doesn`t work the resones for the error is because it has been made to convert any problem, any errors usually mean that it already been done, and it having problem doing it again. It`s like asking the pope to convert to christianty.