Article ID: 183621
Article Last Modified on 3/14/2005
Dim Con as rdoConnection
Dim ConString As String
On Error Resume Next
'establish the connection to the database
ConString = "UID=<your userID>;PWD=<your password>;DATABASE=Pubs;"
ConString = ConString & "SERVER=<your server name>;"
ConString = ConString & "DRIVER={SQL Server};DSN='';"
Set Con = rdoEnvironments(0).OpenConnection(dsname:="", _
prompt:=rdDriverNoPrompt, connect:=ConString)
'make the Master database the current database
Con.Execute "use Master"
'add a login called "TestLogin", which has a password equal to
'"password"; Pubs is specified as the default database for this login
Con.Execute "exec sp_addlogin TestLogin, password, Pubs"
'make Pubs the current database and add TestLogin as a user to Pubs
'by default, TestLogin will be added to the Public group
Con.Execute "use Pubs"
Con.Execute "exec sp_adduser TestLogin"
'now add a group called TestGroup to Pubs and add the TestLogin user to
'the TestGroup group
Con.Execute "exec sp_addgroup TestGroup"
Con.Execute "exec sp_changegroup TestGroup, TestLogin"
Con.Close
Dim Con As New ADODB.Connection
Dim ConString As String
On Error Resume Next
ConString = "UID=<your userID>;PWD=<your password>;DATABASE=Pubs;"
ConString = ConString & "SERVER=<your server name>;"
ConString = ConString & "DRIVER={SQL Server};DSN='';"
With Con
.Open ConString
.Execute "use Master"
'add a login called "TestLogin," which has a password equal to
'"password"; Pubs is specified as the default database for this login
.Execute "exec sp_addlogin TestLogin, password, Pubs"
'make Pubs the current database and add TestLogin as a user to Pubs
'by default, TestLogin will be added to the Public group
.Execute "use Pubs"
.Execute "exec sp_adduser TestLogin"
'now add a group called TestGroup to Pubs and add the TestLogin user
'to the TestGroup group
.Execute "exec sp_addgroup TestGroup"
.Execute "exec sp_changegroup TestGroup, TestLogin"
.close
End With
Additional query words: SQLserver
Keywords: kbhowto kbrdo KB183621