非常好用的asp备份,还原SQL数据库的代码
2018-09-06 12:23
<formmethod=postname=myformaction=?action=backupdatabase>
选择操作:
<inputtype=radioname=actid=act_backupvalue=backup>
<labelfor=act_backup>备份</label>
<inputtype=radioname=actid=act_restorevalue=restore>
<labelfor=act_restore>恢复</label>
<br>
数据库名:
<inputtype=textname=databasenamevalue=<%=request(databasename)%>>
<br>
文件路径:
<inputtype=textname=bak_filevalue=c:\$1.bak>
(备份或恢复的文件路径)<br>
<inputtype=submitvalue=确定id=submit1name=submit1>
</form>
<%
sqlserver数据库的备份与恢复!
ifrequest(action)=backupdatabasethen
dimsqlserver,sqlname,sqlpassword,sqllogintimeout,databasename,bak_file,act
**************************************************************************
sqlserver=127.0.0.1
sqlname=sa
sqlpassword=111
sqllogintimeout=15
databasename=trim(request(databasename))
bak_file=trim(request(bak_file))
bak_file=replace(bak_file,$1,databasename)
act=lcase(request(act))
**************************************************************************
ifdatabasename=then
response.writeinputdatabasename
else
ifact=backupthen
setsrv=server.createobject(sqldmo.sqlserver)
srv.logintimeout=sqllogintimeout
setbak=server.createobject(sqldmo.backup)
bak.database=databasename
bak.devices=files
bak.action=0
bak.replace=true
bak.files=bak_file
bak.sqlbackupsrv
iferr.number>0then
response.writeerr.number&<fontcolor=red><br>
response.writeerr.description&</font>
endif
response.write<fontcolor=green>备份成功!</font>
endif
ifact=restorethen
恢复时要在没有使用数据库时进行!
setsrv=server.createobject(sqldmo.sqlserver)
srv.logintimeout=sqllogintimeout
srv.connectsqlserver,sqlname,sqlpassword
setrest=server.createobject(sqldmo.restore)
rest.action=0fulldbrestore
rest.database=databasename
rest.devices=files
rest.files=bak_file
rest.replacedatabase=trueforcerestoreoverexistingdatabase
iferr.number>0then
response.writeerr.number&<fontcolor=red><br>
response.writeerr.description&</font>
endif
rest.sqlrestoresrv
response.write<fontcolor=green>恢复成功!</font>
else
response.write<fontcolor=red>没有选择操作</font>
endif
endif
endif
%>
文章标题:非常好用的asp备份,还原SQL数据库的代码
文章链接:http://soscw.com/index.php/essay/10279.html