Wednesday, February 15, 2012

error adding Windows group security to database

I'm trying to add a Windows 2000 group to a database with
db_owner rights using the following:
sp_adduser 'MyDomain\sql-admins', 'sql-admins', 'db_owner'
GO
--
I'm encountering the following error:
Server: Msg 15007, Level 16, State 1, Procedure
sp_adduser, Line 15
The login 'MyDomain\sql-admins' does not exist.
--
The login does exist though.
Any help is appreciated.sp_adduser is for backwards compatibility only - try using
sp_grantdbaccess and sp_addrolemember. You can find more information
on these procedures in books online.
You can add a Windows group to the db_owner group using:
EXEC sp_addrolemember 'db_owner', 'YourDomain\YourGroup'
-Sue
On Fri, 21 May 2004 12:42:23 -0700, "Andy"
<anonymous@.discussions.microsoft.com> wrote:

>I'm trying to add a Windows 2000 group to a database with
>db_owner rights using the following:
>--
>sp_adduser 'MyDomain\sql-admins', 'sql-admins', 'db_owner'
>GO
>--
>I'm encountering the following error:
>--
>Server: Msg 15007, Level 16, State 1, Procedure
>sp_adduser, Line 15
>The login 'MyDomain\sql-admins' does not exist.
>--
>The login does exist though.
>Any help is appreciated.|||Thanks Sue, that worked.
However, I'm trying to use the function in an IF statement:
IF @.@.SERVERNAME = 'MyServer'
BEGIN
sp_revokedbaccess 'MyGroup'
GO
sp_grantdbaccess 'MyDomain\MyGroup', 'MyGroup'
GO
sp_addrolemember 'db_owner', 'MyGroup'
GO
END
I get the following error:
Server: Msg 170, Level 15, State 1, Line 3
Line 3: Incorrect syntax near 'sp_revokedbaccess'.
I can execute the commands fine if they're not in the
BEGIN-END statement
Any ideas anyone?

>--Original Message--
>sp_adduser is for backwards compatibility only - try using
>sp_grantdbaccess and sp_addrolemember. You can find more
information
>on these procedures in books online.
>You can add a Windows group to the db_owner group using:
>EXEC sp_addrolemember 'db_owner', 'YourDomain\YourGroup'
>-Sue
>On Fri, 21 May 2004 12:42:23 -0700, "Andy"
><anonymous@.discussions.microsoft.com> wrote:
>
with[vbcol=seagreen]
admins', 'db_owner'[vbcol=seagreen]
>.
>|||Andy,
Try executing the block using something like:
BEGIN
exec sp_revokedbaccess 'MyGroup'
exec sp_grantdbaccess 'MyDomain\MyGroup', 'MyGroup'
exec sp_addrolemember 'db_owner', 'MyGroup'
END
-Sue
On Mon, 24 May 2004 07:45:42 -0700, "Andy"
<anonymous@.discussions.microsoft.com> wrote:
[vbcol=seagreen]
>Thanks Sue, that worked.
>However, I'm trying to use the function in an IF statement:
>IF @.@.SERVERNAME = 'MyServer'
> BEGIN
> sp_revokedbaccess 'MyGroup'
> GO
> sp_grantdbaccess 'MyDomain\MyGroup', 'MyGroup'
> GO
> sp_addrolemember 'db_owner', 'MyGroup'
> GO
> END
>I get the following error:
>Server: Msg 170, Level 15, State 1, Line 3
>Line 3: Incorrect syntax near 'sp_revokedbaccess'.
>I can execute the commands fine if they're not in the
>BEGIN-END statement
>Any ideas anyone?
>
>information
>with
>admins', 'db_owner'|||It worked.
My SQL is appearently a bit rusty, thanks again.
-Andy

>--Original Message--
>Andy,
>Try executing the block using something like:
>BEGIN
> exec sp_revokedbaccess 'MyGroup'
> exec sp_grantdbaccess 'MyDomain\MyGroup', 'MyGroup'
> exec sp_addrolemember 'db_owner', 'MyGroup'
> END
>-Sue
>On Mon, 24 May 2004 07:45:42 -0700, "Andy"
><anonymous@.discussions.microsoft.com> wrote:
>
statement:[vbcol=seagreen]
using[vbcol=seagreen]
more[vbcol=seagreen]
>.
>|||Your welcome...glad it's working for you now.
Don't think it's due to your SQL being rusty...a lot of
people get burned on both the exec and the go issues.
You need to use exec for executing a stored procedure when
the command is not the first command in a batch.
GO delimits a batch. When you put GO keywords inside
Begin...End blocks, the End is not sent to the server in the
same batch with the Begin so it's interpreted as a missing
END. You end up with the same effects you get as if you were
missing the closing parenthesis.
-Sue
On Mon, 24 May 2004 11:44:05 -0700,
<anonymous@.discussions.microsoft.com> wrote:
[vbcol=seagreen]
>It worked.
>My SQL is appearently a bit rusty, thanks again.
>-Andy
>
>statement:
>using
>more

No comments:

Post a Comment