posted on Thursday, October 26, 2006 12:07 PM by marathonsqlguy

Revoking a Database Role using SMO

A developer posed an interesting problem in the MSDN SMO forum about removing certain permissions from a database user, and were attempting to use the ObjectPermissionSet object to adjust the permissions. In fact they were attempting to revoke the db_owner database role from the user, so I posted the following code to help them solve the problem:

	Dim objDBRole As DatabaseRole
	objDBRole = objDatabase.Roles("db_owner")
	objDBRole.DropMember(TextBox2.Text)

It's sometimes difficult to determine the proper objects required to make a change, but between the Object Browser and the BOL you can usually figure things out.

By the way, if you're interested in a little bio and picture of me, Microsoft Learning was kind enough to feature me on their site.

Allen

Comments