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