'Add an SQL Server2000 User Function in ASP and create a database, grant the DBO permission '****************** note: the SQL Server authentication method should not be set to Windows, * allow remote SQL server connection * the function has passed the test. If you have any questions, please contact me., some SQL server management operations will be introduced in the futureProgram
'Parameter: strloginname: New Login Name, strpwd: Login Name password, strdbname: new database name' local variable description in the function: strserver: server machine name (local), struid: SQL administrator, 'strsapwd: SQL administrator password. The above three variables should be set according to your situation
'The function is mainly implemented by calling the system stored procedure.
'Note: this function is not fault tolerant. If an error occurs, you can confirm that your SQL server settings are incorrect, or the login account or database 'call addusertomssql ("testlogin", "iamhere", "db_test") already exists ")
Sub addusertomssql (strloginname, strpwd, strdbname) 'defines the server variables and System Administrator Logon Information. Modify the parameters according to the actual situation.
Dim strserver, struid, strsapwd strserver = "(local)" struid = "sa" strsapwd = "" dim conn' database connection
Dim strdsn 'database connection string
Dim strcmd' command string
Strdsn = "driver = {SQL Server}; server =" & strserver & "; uid =" & struid & "; Pwd =" & strsapwd &"; database = Master "'establish a connection with the database master set conn = server. createobject ("ADODB. connection ") Conn. open strdsn
'Create a database strcmd = "create database" & strdbname conn.exe cute (strcmd) 'create a Logon account strcmd = "sp_addlogin'" & strloginname &"', '"& strpwd &"', '"& strdbname &"' "conn.exe cute (strcmd) Conn. close
'Establish a connection with the new database and grant the New login account the right to access the new database strdsn = "driver = {SQL Server}; server =" & strserver &"; uid = "& struid &";
Pwd = "& stsarpwd &"; database = "& strdbname strcmd =" sp_grantdbaccess' "& strloginname &" '"conn. Open strdsn conn.exe cute (strcmd)
'Make the New login account the owner of the new database strcmd = "sp_addrolemember 'db _ owner', '" & strloginname & "'" conn.exe cute (strcmd) 'to close and release the connection Conn. close set conn = nothing response. write "user" & strloginname & "created successfully !, A Database "& strdbname &" has been created for him &"! "End sub