473,395 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

automated role creation

i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @rolename does
not work).

Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@rolename
etc.

So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!

Thanks much for any help

Oct 16 '06 #1
4 3515
You create a role in the database then add users/roles to that role as
you say.

sp_grantdbaccess is used to allow users access to the database whereas a
role is a means of allowing permissions to be allocated to all users in
that role.

You can though administer via nt roles which may be the sort of thing
you are looking for.

www.nigelrivett.net
*** Sent via Developersdex http://www.developersdex.com ***
Oct 16 '06 #2
cy********@gmail.com wrote:
i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @rolename does
not work).

Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@rolename
etc.

So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!

Thanks much for any help
You should use the T-SQL syntax instead of the SPs whenever possible,
as SPs might get obsolete at some point.

Basically, here is a simple process to handle the users and roles.

1) Create a server-wide login:
create login user1 with password = '123';

2) Create the user in your database:
use database1;
create user user1;

3) Create a role in your database:
use database1;
create role role1;

4) Add the user to the role:
use database1;
exec sp_addrolemember 'role1','user1';

5) Give some permissions to the role:
grant control to role1;

Whenever you need to fine-tune the permissions, you just use the
"grant" keyword on the role.

Note: "grant control" gives all permissions on the database objects,
most of the time you should be more restrictive.

Regards,
lucm

Oct 16 '06 #3
This sequence is fine, but the problem is that the "grant control to
role1" portion does not add the role to the database permissions list.
Perhaps this is just a bug in the way SQL Server Mgmt Studio displays
roles and users. For instance, when I do a "sp_grantdbaccess
@username", the user shows up in the database's permissions list. Doing
a "create role @rolename" then "grant control to @rolename" still does
not add the role to the "users or roles" permission list under Database
Properties.

I need to test out whether the permissions assigned to the role using
the steps above propagate down to the users irrespective of the
Database Properties issues I've described. However, it seems that there
could be synchronization issues if the "grant control" execution is not
reflected in the permissions gui (for example if someone decides to add
the same role again, what happens?).

Thanks much for the responses tho'.

On Oct 16, 12:32 pm, l...@iqato.com wrote:
cyberto...@gmail.com wrote:
i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @rolename does
not work).
Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@rolename
etc.
So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!
Thanks much for any helpYou should use the T-SQL syntax instead of the SPs whenever possible,
as SPs might get obsolete at some point.

Basically, here is a simple process to handle the users and roles.

1) Create a server-wide login:
create login user1 with password = '123';

2) Create the user in your database:
use database1;
create user user1;

3) Create a role in your database:
use database1;
create role role1;

4) Add the user to the role:
use database1;
exec sp_addrolemember 'role1','user1';

5) Give some permissions to the role:
grant control to role1;

Whenever you need to fine-tune the permissions, you just use the
"grant" keyword on the role.

Note: "grant control" gives all permissions on the database objects,
most of the time you should be more restrictive.

Regards,
lucm
Oct 16 '06 #4
Never mind, I'm an idiot - adding the 'grant control' actually adds the
role to the database control set!!! My apologies. I was going under the
impression that just assigning "alter" permissions would be sufficient,
rather than "control" permissions.

Thanks much.

cybertoast wrote:
This sequence is fine, but the problem is that the "grant control to
role1" portion does not add the role to the database permissions list.
Perhaps this is just a bug in the way SQL Server Mgmt Studio displays
roles and users. For instance, when I do a "sp_grantdbaccess
@username", the user shows up in the database's permissions list. Doing
a "create role @rolename" then "grant control to @rolename" still does
not add the role to the "users or roles" permission list under Database
Properties.

I need to test out whether the permissions assigned to the role using
the steps above propagate down to the users irrespective of the
Database Properties issues I've described. However, it seems that there
could be synchronization issues if the "grant control" execution is not
reflected in the permissions gui (for example if someone decides to add
the same role again, what happens?).

Thanks much for the responses tho'.

On Oct 16, 12:32 pm, l...@iqato.com wrote:
cyberto...@gmail.com wrote:
i seem to have some misunderstanding about how roles work in sql server
2005. i see that i can add a role to a database
(dbname->[right-click]->properties->permissions->[add ...]. THis allows
me to add either users or roles. Users can be added programmatically
using sp_grantdbaccess @username, but this does not allow for addition
of roles to access the database (i.e., sp_grantdbaccess @rolename does
not work).
Is there some other command that is used to add a role to the
database's permissions list? Seems there must be since all the other
parts of the permissions chain work quite well:
* sp_addrole
* sp_addrolemember
* grant <permissionon role::@rolename
etc.
So the missing ingredient of something like sp_grantdbroleaccess is
what I need and can't seem to find it anywhere!
Thanks much for any helpYou should use the T-SQL syntax instead of the SPs whenever possible,
as SPs might get obsolete at some point.

Basically, here is a simple process to handle the users and roles.

1) Create a server-wide login:
create login user1 with password = '123';

2) Create the user in your database:
use database1;
create user user1;

3) Create a role in your database:
use database1;
create role role1;

4) Add the user to the role:
use database1;
exec sp_addrolemember 'role1','user1';

5) Give some permissions to the role:
grant control to role1;

Whenever you need to fine-tune the permissions, you just use the
"grant" keyword on the role.

Note: "grant control" gives all permissions on the database objects,
most of the time you should be more restrictive.

Regards,
lucm
Oct 16 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: craig | last post by:
I am working on my first .NET development project that involves custom role-based security per the project requirements. This lead to a general design issue this week that really caused us some...
3
by: Bryan Capps | last post by:
I'm developing an ms-access db which keeps track of some insurance claims. When I recieve a new claim, I want to be able to have the db create a standard set of folders for that claim, if they...
2
by: Jesper Stocholm | last post by:
I have implemented role-based security within my ASP.Net application. However, it seems the role is not passed to the authentication ticket I create. I want to use it to display/hide some...
3
by: Smithers | last post by:
I have indeed googled this group and googled the 'net, and what I came up with was that if I want to have an automated process that ZIPs a file, I need to come up with 600 bucks for PKWare's server...
2
by: Rob Richardson | last post by:
Greetings! It seems to me that there is room for a lot of improvement in automatic generation of database objects. If I create a data adapter from a table shown in the Server Explorer, I get...
5
by: Ben R. | last post by:
My website uses a custome membership and role provider. I can use a custom login control and user creation control and can debug my providers while doing so with breakpoints. However, when I launch...
3
by: jsmith31 | last post by:
hi to everyone, I tried to create a function that includes a role creation with the rolename and password as parameters to be called by other function but the postgresql raises an error like that: ...
1
by: gouse | last post by:
Hi All I have 1 Admin role and 3 non admin roles (like user_1,user_2....). There are 10 Database (like 1,2,3....10) in my PostgreSQL sever. I am admin and want to assign access (no objects...
2
by: Anthony Smith | last post by:
I have a user object that is set when a user logs in. There are also permissions that I get about the user from a web service. Currently I take the results from those web services and store them as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.