ASP creates accounts and permissions in SQL Server 2000

Source: Internet
Author: User
Tags sql server management

'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. If you have any questions, please contact me., some SQL server management operations will be introduced in the futureProgram
'Parameter: strloginname: New Login Name, strpwd: Login Name password, strdbname: new database name' local variable description in the function: strserver: server machine name (local), struid: SQL administrator, 'strsapwd: SQL administrator password. The above three variables should be set according to your situation
'The function is mainly implemented by calling the system stored procedure.
'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 'call addusertomssql ("testlogin", "iamhere", "db_test") already exists ")
Sub addusertomssql (strloginname, strpwd, strdbname) 'defines the server variables and System Administrator Logon Information. Modify the parameters 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
'Create a database strcmd = "create database" & strdbname conn.exe cute (strcmd) 'create a Logon account strcmd = "sp_addlogin'" & strloginname &"', '"& strpwd &"', '"& strdbname &"' "conn.exe cute (strcmd) Conn. close
'Establish a connection with the new database and grant the New login account the right to access the new database 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 login account the owner of the new database strcmd = "sp_addrolemember 'db _ owner', '" & strloginname & "'" conn.exe cute (strcmd) 'to close and release the connection Conn. close set conn = nothing response. write "user" & strloginname & "created successfully !, A Database "& strdbname &" has been created for him &"! "End sub

Related Article

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.