非常好用的asp备份,还原SQL数据库的代码_ASP教程-查字典教程网
非常好用的asp备份,还原SQL数据库的代码
非常好用的asp备份,还原SQL数据库的代码
发布时间:2016-12-29 来源:查字典编辑
摘要:选择操作:备份恢复数据库名:文件路径:(备份或恢复的文件路径)0thenresponse.writeerr.number&""respons...

<formmethod="post"name="myform"action="?action=backupdatabase">

选择操作:

<inputtype="radio"name="act"id="act_backup"value="backup">

<labelfor=act_backup>备份</label>

<inputtype="radio"name="act"id="act_restore"value="restore">

<labelfor=act_restore>恢复</label>

<br>

数据库名:

<inputtype="text"name="databasename"value="<%=request("databasename")%>">

<br>

文件路径:

<inputtype="text"name="bak_file"value="c:$1.bak">

(备份或恢复的文件路径)<br>

<inputtype="submit"value="确定"id=submit1name=submit1>

</form>

<%

'sqlserver数据库的备份与恢复!

ifrequest("action")="backupdatabase"then

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.write"inputdatabasename"

else

ifact="backup"then

setsrv=server.createobject("sqldmo.sqlserver")

srv.logintimeout=sqllogintimeout

srv.connectsqlserver,sqlname,sqlpassword

setbak=server.createobject("sqldmo.backup")

bak.database=databasename

bak.devices=files

bak.action=0

bak.initialize=1

'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="restore"then

'恢复时要在没有使用数据库时进行!

setsrv=server.createobject("sqldmo.sqlserver")

srv.logintimeout=sqllogintimeout

srv.connectsqlserver,sqlname,sqlpassword

setrest=server.createobject("sqldmo.restore")

rest.action=0'fulldbrestore

rest.database=databasename

rest.devices=files

rest.files=bak_file

rest.replacedatabase=true'forcerestoreoverexistingdatabase

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教程学习
    热门ASP教程学习
    编程开发子分类