asp Access数据备份,还原,压缩类代码
程序员文章站
2022-03-31 14:01:39
<% '...
<!--#include file="config.asp" -->
<!--#include file="fun.asp" -->
<%
'数据库管理类
class datas
'备份
public sub bk()
set fso=server.createobject("scripting.filesystemobject")
fso.copyfile server.mappath(sitedatapath),server.mappath(sitedatabakpath)
set fso=nothing
response.write("<script language=javascript><!--
alert('备份成功!');window.location.href='datamanage.asp'
// --></script>")
end sub
'还原
public sub rt()
sdpath = server.mappath(sitedatapath)
sdbpath = server.mappath(sitedatabakpath)
set fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(sdbpath) then
fso.copyfile sdbpath,sdpath
set fso=nothing
response.write("<script language=javascript><!--
alert('成功:你已经成功恢复数据库!');window.location.href='datamanage.asp?action=rt'
// --></script>")
else
response.write("<script language=javascript><!--
alert('失败:请检查路径和数据库名是否存在');window.location.href='datamanage.asp?action=rt'
// --></script>")
end if
end sub
'压缩
public sub dc()
sdbpath = server.mappath(sitedatabakpath)
set fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(sdbpath) then
set engine =server.createobject("jro.jetengine")
if request("boolis") = "97" then
engine.compactdatabase "provider=microsoft.jet.oledb.4.0;data source=" & sdbpath, _
"provider=microsoft.jet.oledb.4.0;data source=" & sdbpath & "_temp.mdb;" _
& "jet oledb:engine type=" & jet_3x
else
engine.compactdatabase "provider=microsoft.jet.oledb.4.0;data source=" & sdbpath, _
"provider=microsoft.jet.oledb.4.0;data source=" & sdbpath & "_temp.mdb"
end if
fso.copyfile sdbpath & "_temp.mdb",sdbpath
fso.deletefile(sdbpath & "_temp.mdb")
set fso = nothing
set engine = nothing
response.write("<script language=javascript><!--
alert('成功:数据库已经压缩成功!');window.location.href='datamanage.asp?action=dc'
// --></script>")
else
response.write("<script language=javascript><!--
alert('失败:数据库压缩失败,请检查路径和数据库名是否存在!');window.location.href='datamanage.asp?action=dc'
// --></script>")
end if
end sub
end class
%>
<!--#include file="fun.asp" -->
<%
'数据库管理类
class datas
'备份
public sub bk()
set fso=server.createobject("scripting.filesystemobject")
fso.copyfile server.mappath(sitedatapath),server.mappath(sitedatabakpath)
set fso=nothing
response.write("<script language=javascript><!--
alert('备份成功!');window.location.href='datamanage.asp'
// --></script>")
end sub
'还原
public sub rt()
sdpath = server.mappath(sitedatapath)
sdbpath = server.mappath(sitedatabakpath)
set fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(sdbpath) then
fso.copyfile sdbpath,sdpath
set fso=nothing
response.write("<script language=javascript><!--
alert('成功:你已经成功恢复数据库!');window.location.href='datamanage.asp?action=rt'
// --></script>")
else
response.write("<script language=javascript><!--
alert('失败:请检查路径和数据库名是否存在');window.location.href='datamanage.asp?action=rt'
// --></script>")
end if
end sub
'压缩
public sub dc()
sdbpath = server.mappath(sitedatabakpath)
set fso=server.createobject("scripting.filesystemobject")
if fso.fileexists(sdbpath) then
set engine =server.createobject("jro.jetengine")
if request("boolis") = "97" then
engine.compactdatabase "provider=microsoft.jet.oledb.4.0;data source=" & sdbpath, _
"provider=microsoft.jet.oledb.4.0;data source=" & sdbpath & "_temp.mdb;" _
& "jet oledb:engine type=" & jet_3x
else
engine.compactdatabase "provider=microsoft.jet.oledb.4.0;data source=" & sdbpath, _
"provider=microsoft.jet.oledb.4.0;data source=" & sdbpath & "_temp.mdb"
end if
fso.copyfile sdbpath & "_temp.mdb",sdbpath
fso.deletefile(sdbpath & "_temp.mdb")
set fso = nothing
set engine = nothing
response.write("<script language=javascript><!--
alert('成功:数据库已经压缩成功!');window.location.href='datamanage.asp?action=dc'
// --></script>")
else
response.write("<script language=javascript><!--
alert('失败:数据库压缩失败,请检查路径和数据库名是否存在!');window.location.href='datamanage.asp?action=dc'
// --></script>")
end if
end sub
end class
%>
上一篇: 办公室内外的搞笑趣事!笑喷了