' The following is a SQL server2000 user function added to the ASP, and to create a database, give him the dbo permissions ' **************** NOTE: SQL Server is not validated in a Windows-only way, ' *********** Allow remote SQL Server connection ' **************** This function has passed the test **************************** ' What's the problem? Welcome to communicate with me, and then introduce some management procedures for SQL 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
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.