Excluding windows users from script
tchaplin@miningis.com.au
Posts: 20
I am trying to not include windows users in my scripting app. I am using the following code.
But they still appear in the differences script.
I think this is because they have been granted permissions on objects that I am including, like store procedures.
How do make it so the windows aren't included, no matter permissions they have?
foreach (Difference difference in differences) { difference.Selected = true; if (difference.DatabaseObjectType == ObjectType.User) { RedGate.SQLCompare.Engine.User u = (RedGate.SQLCompare.Engine.User) difference.ObjectIn1; if(u.UserType == UserType.WindowsUser) { difference.Selected = false; } }
But they still appear in the differences script.
I think this is because they have been granted permissions on objects that I am including, like store procedures.
How do make it so the windows aren't included, no matter permissions they have?
Comments
If you're using Options.Default, instead use Options.Default ^ Options.IncludeDependencies.
You'll have to make sure that you've selected dependent objects yourself, though, and if the users are actually needed and not present then the script might not run.
You might also want to use Options.IgnoreUsers (which is actually short for 'ignore users' permissions and role memberships' - it will not attempt to synchronize permissions and role memberships held by users, which might help the script run smoother) and Options.IgnorePermissions (which will not synchronize any permissions) on both comparison and synchronization, if you don't need to synchronize other occasions where those things appear.
Redgate Software
I can add Options.IgnoreUsers and Options.IgnorePermissions (I haven't found one for schemas) but then *none* of the role memberships or permissions are included. I would like the role memberships, permissions and schemas for Sql users to be included.
Is there way to exclude Windows users and all their dependant objects, whilst leaving all Sql users with their roles, permisions and schemas intact?
For your information, I am actually comparing the database against null to get a database create script - I am not interested in synchronizing 2 databases at this stage. Basically I'm bring back scripts from a client's office and rebuilding them in my office - and so I can't include Windows from another domain. Is there another way around it? Can I convert Windows users to Sql users?
Then I was thinking of adding on code to remove users from roles if they are windows users, e.g. add this onto the end of the if block
Except that it seems I can't remove users from a role here ...
Then there is also the matter of permissions, I need to be able to cycle through all database objects that have permissions (is there an interface for this?) and remove the user from the from the grant statement ... is that possible?
Redgate Software