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