Add user to SQL Server 2000 using vb.net

M

Mark

Hi all,

Can anyone tell me how I can add a new user to an existing SQL Server 2000
database programmatically using vb.net.

Any help will be very much appreciated. I have had a good Google around but
have been unable to find anything.

Many thanks in advance.
 
K

Ken Tucker [MVP]

Hi,


Simple example. Adds a user to the northwind database.

Imports System.Data.SqlClient

Module Module1

Sub Main()

Dim conn As SqlConnection

Dim cmd As SqlCommand

Dim strConn As String

strConn = "Server = " & Environment.MachineName

strConn += "\VSdotNET; Database = NorthWind; Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

conn.Open()

cmd = New SqlCommand("sp_grantdbaccess 'Ken'", conn)

cmd.ExecuteNonQuery()

conn.Close()

End Sub

End Module



Ken
 
G

Guest

Many Thanks Ken.

Will this still work without using Integrated Security ?
The app I am developing will use SQL Usernames and Passwords.

Thank you again..... Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top