Re: Please Help
From: Bob Barrows (reb_01501@yahoo.com)
Date: 01/14/03
- Next message: Ray: "Hide SQL tables"
- Previous message: Magnus Pettersson: "Re: Application roles Please Help!"
- In reply to: oj: "Re: Please Help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
From: "Bob Barrows" <reb_01501@yahoo.com> Date: Tue, 14 Jan 2003 07:08:16 -0500
oj,
Remember, he wants to do this in a stored procedure, thus preventing the use
of the keyword "use". It sounds as if he could use this code in a stored
procedure created in the Master database ... let's see ... yes, that works.
David, create a procedure in Master using oj's code - something like this:
use master
go
create procedure usp_AddUser (
@role sysname, @user sysname)
AS
--select @role='db_datareader',@user='abc'
--create new sql login
exec sp_addlogin @user,@user
--grant access to pubs db
exec pubs..sp_adduser @user
--add to pubs datareader role
exec pubs..sp_addrolemember @role,@user
--grant access to test db
exec test..sp_adduser @user
--add to test datareader role
exec test..sp_addrolemember @role,@user
Then execute it in your other stored procedure: exec master..usp_AddUser
<role>,<name>
Thanks,
oj
"oj" <nospam_ojngo@home.com> wrote in message
news:uZ2AMI4uCHA.2288@TK2MSFTNGP09...
> here is how to do it without dynamic sql...
>
> e.g.
> use master
> go
> declare @role sysname, @user sysname
> select @role='db_datareader',@user='abc'
>
> --create new sql login
> exec sp_addlogin @user,@user
> --grant access to pubs db
> exec pubs..sp_adduser @user
> --add to pubs datareader role
> exec pubs..sp_addrolemember @role,@user
> --see if the security is set
> exec pubs..sp_helpuser @user
>
> --
> -oj
> http://www.rac4sql.net
>
>
> "David Lucus" <davidl@studentlife.tamu.edu> wrote in message
> news:etA5uu0uCHA.2512@TK2MSFTNGP11...
> > I have a stored procedure that adds new sql server accounts from the
> > web.
> > there are 2 databases that need teh login. The database where the
> > stored
> > procedure resides has no problems granting roles and db access
> permissions,
> > however when i try to give it permissions to the other database nothing
> > is
> > happening. It is not adding a user to the roles or throwing an error.
> here
> > is the code i am using to add the user to the second db
> >
> > EXECUTE DBName.dbo.sp_grantdbaccess @newname
> >
> > EXECUTE DBName.dbo.sp_addrolemember @sturolename, @newname
> >
> > where @newname is the variable with the name, and @sturolename is the
> > role
> > name.
> >
> > if anyone has any ideas please help.
> >
> > thx,
> > David
> >
> >
>
>
- Next message: Ray: "Hide SQL tables"
- Previous message: Magnus Pettersson: "Re: Application roles Please Help!"
- In reply to: oj: "Re: Please Help"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|