So now that we have the login and the user set up, how do we actually assign permissions?
I prefer to assign permissions to roles and add users to roles which mirrors the user/groups of windows, so going down that path we have to create a role (going under Security –> Roles):
CREATE ROLE [TestRole]
Now comes the part that isn’t very intuitive. To associate a user with a role you have to go back to the Solution Explorer and actually create a generic user script file (see here), you can call it whatever you want and place it wherever you want in the project, however if you reverse engineer the database it will be called <ProjectName>.rolememberships.sql under the schema objects folder:
EXECUTE sp_addrolemember @rolename = N'TestRole', @membername = N'TestUser';
Now we have the role defined and the users as part of the role, we can start adding permissions, this is where you’ll have loads of fun provided you enjoy manually editing xml documents. Again in Solution Explorer under Properties you’ll see a Database.sqlpermissions.sql file:
In there you’ll see some xml with examples:
<?xml version="1.0" encoding="utf-8"?> <?XML:NAMESPACE PREFIX = [default] urn:Microsoft.VisualStudio.Data.Schema.Permissions NS = "urn:Microsoft.VisualStudio.Data.Schema.Permissions" />
So as you can see while it’s not that intuitive it is pretty straight forward.




![SolutionExplorer[4] SolutionExplorer[4]](http://www.aaronlowe.net/wp-content/uploads/SolutionExplorer%5B4%5D.png)

![MySchema[5] MySchema[5]](http://www.aaronlowe.net/wp-content/uploads/MySchema%5B5%5D.png)

