ASP in SQL Server 2000 new account and permissions _ database related

Source: Internet
Author: User
Tags create database







 Sub addusertomssql (strloginname,strpwd,strdbname) 
defines server variables and system administrator logon information, modifying
Dim strserver,struid as appropriate. Strsapwd
strserver= (local)
struid= "sa"
strsapwd= "
Dim Conn ' Database Connection
Dim strDSN ' Database Connection string
Dim Str CMD ' command string
strdsn= "Driver={sql server};server=" &StrServer& "uid=" &StrUid& ";p wd=" &strsapwd & ";d Atabase=master"
Establish connection to database Master
Set Conn = Server.CreateObject ("ADODB. Connection ")
Conn.Open strdsn
' 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
' establishes a connection to the new database and assigns the new logon account the right to access the new database
strdsn= ' Driver={sql server}; = "&StrServer&"; uid= "&StrUid&";
  Conn.Open strdsn 
Conn.execute (strcmd)
' Make the new login account the owner of the new database
strcmd= ' sp_ Addrolemember ' db_owner ', ' &StrLoginName& ' '
Conn.execute (strcmd)
' Close release connection
Conn.close
Set Conn=nothing
Response.Write "User &StrLoginName&" was successfully established and a database "&StrDBName&" has been established 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.