How asp creates an account in SQLSER2k and grants permissions to the account

Source: Internet
Author: User
Add a sqlserver2000 User Function in asp, and grant the dbo permission to a database ****************** to the user. Note: do not select windows as the authentication method for sqlserver, * ************** allow remote sqlserver connection ****************** this function has passed test *************

'Add an SQL server2000 User Function in asp and create a database, grant the dbo permission '****************** note: the SQL server authentication method should not be set to windows, * allow remote SQL server connection * the function has passed the test *************

'Add an SQL server2000 User Function in asp, create a database, and grant the user'sPermission

* Note: do not select windows as the SQL server verification method,

* Allows remote SQL server connection.

* This function has passed the test ****************** **********

'If you have any questions, please contact me. Some SQL server Management procedures will be launched in the future.

'Parameter: StrLoginName: New Login Name, StrPwd: Login Name password, StrDBName:NewDatabase Name

'Description of local variables in the function: StrServer: name of the server (local on the local machine), StrUid: SQL administrator,

'Strsapwd: SQL administrator password. The above three variables should be set according to your situation

'The function mainly calls the system stored procedureImplementationOf

'Note: this function is not fault tolerant. If an error occurs, you can confirm that your SQL server settings are incorrect, or the login account or database already exists.

'Call AddUserToMSSQL ("testlogin", "iamhere", "db_test ")

Sub AddUserToMSSQL (StrLoginName, StrPwd, StrDBName)

'Define the server variables and System Administrator Logon Information, and modify the information according to the actual situation.

Dim StrServer, StrUid, StrSaPwd

StrServer = "(local )"

StrUid = "sa"

StrSaPwd = ""

Dim conn' database connection

Dim StrDSN 'database connection string

Dim strcmd' command string

StrDSN = "driver = {SQL server}; server =" & StrServer & "; uid =" & StrUid & "; pwd =" & StrSaPwd & "; database = master"

'Establish a connection with the database master

Set Conn = Server. CreateObject ("ADODB. Connection ")

Conn. Open StrDSN

'New1. Database

StrCmd = "create database" & StrDBName

Conn.exe cute (StrCmd)

'New1. Logon account

StrCmd = "sp_addlogin '" & StrLoginName & "', '" & StrPwd & "', '" & StrDBName &"'"

Conn.exe cute (StrCmd)

Conn. Close

'Establish andNewDatabase Connection and grant access to the new Login AccountNewDatabase Rights

StrDSN = "driver = {SQL server}; server =" & StrServer & "; uid =" & StrUid & "; pwd =" & StSarPwd & "; database =" & StrDBName

StrCmd = "sp_grantdbaccess'" & StrLoginName &"'"

Conn. Open StrDSN

Conn.exe cute (StrCmd)

'Make the new Logon account becomeNewDatabase owner

StrCmd = "sp_addrolemember 'db _ owner', '" & StrLoginName &"'"

Conn.exe cute (StrCmd) 257108.com

'Close the release connection

Conn. Close

Set Conn = Nothing

Response. Write "user" & StrLoginName & "created successfully !, A Database "& StrDBName &" has been created for him &"! "

End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.