Add a sqlserver2000 User Function in asp, and grant the dbo permission to a database ****************** to the user. Note: do not select windows as the authentication method for sqlserver, * ************** allow remote sqlserver connection ****************** this function has passed test *************
'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 *************
'Add an SQL server2000 User Function in asp, create a database, and grant the user'sPermission
* Note: do not select windows as the SQL server verification method,
* Allows remote SQL server connection.
* This function has passed the test ****************** **********
'If you have any questions, please contact me. Some SQL server Management procedures will be launched in the future.
'Parameter: StrLoginName: New Login Name, StrPwd: Login Name password, StrDBName:NewDatabase Name
'Description of local variables in the function: StrServer: name of the server (local on the local machine), StrUid: SQL administrator,
'Strsapwd: SQL administrator password. The above three variables should be set according to your situation
'The function mainly calls the system stored procedureImplementationOf
'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 already exists.
'Call AddUserToMSSQL ("testlogin", "iamhere", "db_test ")
Sub AddUserToMSSQL (StrLoginName, StrPwd, StrDBName)
'Define the server variables and System Administrator Logon Information, and modify the information 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
'New1. Database
StrCmd = "create database" & StrDBName
Conn.exe cute (StrCmd)
'New1. Logon account
StrCmd = "sp_addlogin '" & StrLoginName & "', '" & StrPwd & "', '" & StrDBName &"'"
Conn.exe cute (StrCmd)
Conn. Close
'Establish andNewDatabase Connection and grant access to the new Login AccountNewDatabase Rights
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 Logon account becomeNewDatabase owner
StrCmd = "sp_addrolemember 'db _ owner', '" & StrLoginName &"'"
Conn.exe cute (StrCmd) 257108.com
'Close the release connection
Conn. Close
Set Conn = Nothing
Response. Write "user" & StrLoginName & "created successfully !, A Database "& StrDBName &" has been created for him &"! "
End Sub