ASP creates new accounts and permissions in SQL Server 2k

Source: Internet
Author: User
Tags administrator password create database
Server ' below to add a SQL server2000 user function to the ASP, and to create a database that gives him the dbo permissions ' **************** NOTE: SQL Server authentication is not selected for Windows only, ' * * * Allow remote SQL Server connection ' **************** This function has passed the test **************************** ' What's the problem welcome and I exchange, later will launch the SQL Some management procedures for the server
' Parameters: Strloginname: New login name, strpwd: login password, strdbname: New database name ' function local variable description: strserver: Server's machine name (local locally), Struid:sql administrator, ' Strsapwd:sql the administrator password. The above three variables should be set according to your situation
' This function primarily invokes the system stored procedure to implement the
' Note: This function does not have fault-tolerant processing, if there is an error, you can determine that there is a problem with your SQL Server settings, or that the login account or the database ' call Addusertomssql ' ("Testlogin", "Iamhere", "Db_test") )
Sub addusertomssql (strloginname,strpwd,strdbname) ' defines server variables and system administrator login information, modifying Dim strserver,struid,strsapwd as appropriate Strserver= "(local)" struid= "sa" strsapwd= "Dim Conn Database Connection Dim strdsn ' Database Connection string Dim strcmd ' command String strdsn= ' Driver={sql ser Ver};server= "&StrServer&" uid= "&StrUid&";p wd= "&StrSaPwd&";d atabase=master "" Establish a connection to the database master set Conn = Server.CreateObject ("ADODB.") Connection ") Conn.Open strDSN ' Create a new database strcmd= ' CREATE database ' &strdbname conn.execute (strcmd) ' Create a new login account strcmd= ' sp_ Addlogin ' &StrLoginName& ', ' &StrPwd& ' ', ' ' &StrDBName& ' ', Conn.execute (strcmd) conn.close ' Establish a connection to the new database and assign the new login account the right to access the new database strdsn= ' Driver={sql server}; Server= "&StrServer&" uid= "&StrUid&";p wd= "&StSarPwd&";d atabase= "&strdbname strcmd=" sp_grantdbaccess ' "&StrLoginName&" "" Conn.Open strDSN Conn.execute (strcmd) ' makes the new login account the owner of the new database strcmd= ' sp_ Addrolemember ' db_owner ', ' &StrLoginName& ' ' Conn.execute (strcmd) ' Off release connection Conn.close Set CoNn=nothing Response.Write "User" &StrLoginName& "successfully established!" and has established a database "&StrDBName&" 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.