Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Add a user from VBA code


Message #1 by david.chapman@d... on Thu, 19 Dec 2002 23:39:38
Try:

CREATE PROCEDURE spAddLogin

    @UserID varchar(10)

AS

-- need to concatenate the value of @UserID to the
-- string literal 'DEVDOMAIN\'
EXEC sp_grantlogin 'DEVDOMAIN\'  + @UserID
EXEC sp_grantdbaccess 'DEVDOMAIN\' +  @UserID
EXEC sp_addrolemember 'OIC', 'DEVDOMAIN\'  + @UserID

GO

(Also, GO is not T-SQL - it's a batch separator. so you can't have it inside
a sproc. If you need to use GO, you need to create separate sprocs for each
batch, and call them from a master sproc.)

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <david.chapman@d...>
Subject: [sql_language] Add a user from VBA code


: I have been trying to add code to my access97  front end that will add a
: new user to the Access2000 server, database and to a role. The following
: code executes correctly in query analyzer. It will not work when executed
: through a passthrough query, (access97 and DAO) The code is built by vba
: I use the same passthrough query to execute SQL update and insert
: commands, so I am confident its connection properties are correct.
:
: USE SSOLicense
: EXEC sp_grantlogin 'DEVDOMAIN\beames'
: GO
: EXEC sp_grantdbaccess 'DEVDOMAIN\beames'
: GO
: EXEC sp_addrolemember 'OIC', 'DEVDOMAIN\beames'
: GO
: Executing the passthrough query causes a runtime error '3146 ODBC--call
: failed'
:
:
: My attempts to create a SP failed to, so either I am having a bad day or
: there is something I don't understand.
:
: CREATE PROCEDURE spAddLogin  @UserID varchar(10) AS
:
: EXEC sp_grantlogin 'DEVDOMAIN\' @UserID
: GO
: EXEC sp_grantdbaccess 'DEVDOMAIN\' @UserID
: GO
: EXEC sp_addrolemember 'OIC', 'DEVDOMAIN\' @UserID
: GO
:
: causes the error "Error 170: Line 3: Incorrect syntax near '@U...'"
:
: As I am a strugling learner I would appreciate any comments or help any
: one can give.


  Return to Index