Wrox Programmer Forums
|
Pro VB Databases Advanced-level VB coding questions specific to using VB with databases. Beginning-level questions or issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 11th, 2003, 04:04 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default sql Users

Hi everybody
I want to add sqlusers from VB6 on sql server but everything i try is going bad.
I log like sa and using ADO to connect but what to do next, how can i use stored procedure sp_addlogin, sp_grantdbaccess or ADOX to create new users and logins on sqlserver2000.

Here is what i tryed, but is not working:

Dim cnLogin As New ADODB.Connection
Dim cmd As ADODB.Command
cnLogin.Open "Provider=" & strProvider & ";User ID=" & strSQLUserID & ";Password=" & strSQLPassword & "Initial Catalog=master;Data Source=" & strServer

Set cmd = New ADODB.Command
    With cmd

        .ActiveConnection = cnLogin
        .CommandType = adCmdStoredProc
        .CommandText = "sp_addlogin"
        .Parameters(1) = Trim(txtIme.Text)
        .Parameters(2) = txtSifra.Text
        .Parameters(3) = "database"
        .Execute


        .CommandText = "sp_grantdbaccess"
        .Parameters(1) = Trim(txtIme.Text)
        .Execute

    End With

Thanks
 
Old September 11th, 2003, 04:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You should add a ; right before the Initial catalog, because currently you have an invalid Connection String.

You may also need to close your connection, and then reopen it using the Database database as the Initial Catalog, as sp_grantdbaccess adds the user to the current database. Not sure about that, though.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old September 11th, 2003, 04:39 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

In addition to this, you can use the following code for the grantDBAccess sproc:


' Open your connection, using the database as the initial catalog.
cnLogin.Open "Provider=" & strProvider & ";User ID=" & strSQLUserID & ";Password=" & strSQLPassword & ";Initial Catalog=database;Data Source=" & strServer

cnLogin.Execute ("EXEC sp_grantdbaccess '" & Trim(txtIme.Text) & "'")

Imar

---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old September 11th, 2003, 07:20 AM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Create SQL Server users programmatically? Dmitriy Pro VB.NET 2002/2003 4 October 29th, 2008 03:14 PM
SQL 2000 Maximum Users reyboy SQL Server 2000 1 June 27th, 2004 09:34 PM
SQL Help on Users and Authentication page 149 seanmayhew BOOK: ASP.NET Website Programming Problem-Design-Solution 1 May 26th, 2004 09:30 AM
Detect Users in SQL reyboy SQL Server 2000 12 July 25th, 2003 09:16 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.