ASP安装SQL数据库和导入数据和建立用户
发表于:2007-06-30来源:作者:点击数:
标签:
% @#on error resume next action=request(action) IF actioninstall THEN % BR center form method=POST action=install.asp?action=install name=form1 填写安装信息BRBR SQL 数据库 管理员:input name=StrUid value=saBR SQL数据库密 码:input name=Str
<%
@#on error resume next
action=request("action")
IF action<>"install" THEN
%>
<BR>
<center>
<form method="POST" action="install.asp?action=install" name="form1">
填写安装信息<BR><BR>
SQL
数据库管理员:<input name=StrUid value=sa><BR>
SQL数据库密 码:<input name=StrSaPwd value=40104529><BR>
SQL数据库地 址:<input name=StrServer value=localhost><BR><BR>
<input name="cmdok" type="submit" class="form1" value="开始安装..." >
</form>
</center>
<%
Else
StrUid=request("StrUid")
StrSaPwd=request("StrSaPwd")
StrServer=request("StrServer")
call CreateDB("info")
call RestoreDB("info","backup\1.bak")
call CreateUser("bin","85228522","info")
response.write "<center><br><BR><input type=@#button@# value=@#安装完成!@# onclick=@#
javascript:
windows.close()@#></center>"
End if
@#step1 建立数据库
Sub CreateDB(StrDBName)
Dim Conn @#数据库连接
Dim StrDSN @#数据库连接字符串
Dim StrCmd @#命令字符串
StrDSN="driver={SQL server};server="&StrServer&";uid="&StrUid&";pwd="&StrSaPwd&";database=master"
@#建立和数据库master的连接
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open StrDSN
@#新建一数据库
StrCmd="CREATE DATABASE "&StrDBName
Conn.execute(StrCmd)
Conn.Close
Set Conn=Nothing
End Sub
@#step2 导入数据
sub RestoreDB(StrDBName,fromBak)
SQL="Restore database " & StrDBName & " from disk=@#"&Server.MapPath(fromBak)&"@#"
set conn=Server.createobject("adodb.connection")
conn.open "driver={SQL server};server="&StrServer&";uid="&StrUid&";pwd="&StrSaPwd
conn.execute SQL
conn.close
set conn=nothing
End sub
@#step3 建立用户
sub CreateUser(StrLoginName,StrPwd,StrDBName)
StrDSN="driver={SQL server};server="&StrServer&";uid="&StrUid&";pwd="&StrSaPwd&";database=master"
@#建立和数据库master的连接
set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open StrDSN
StrCmd="sp_addlogin @#"&StrLoginName&"@#,@#"&StrPwd&"@#,@#"&StrDBName&"@#"
Conn.execute(StrCmd)
Conn.Close
@#建立与新建数据库的连接,并赋给新登录帐号访问新建数据库的权利
StrDSN="driver={SQL server}; server="&StrServer&";uid="&StrUid&";pwd="&StrSaPwd&";database="&StrDBName
StrCmd="sp_gran
tdba
clearcase/" target="_blank" >ccess @#"&StrLoginName&"@#"
Conn.Open StrDSN
Conn.execute(StrCmd)
@#使新登录帐号成为新建数据库的拥有者
StrCmd="sp_addrolemember @#db_owner@#,@#"&StrLoginName&"@#"
Conn.execute(StrCmd)
conn.close
set conn=nothing
End sub
%>
原文转自:http://www.ltesting.net