asp Access数据备份,还原,压缩类代码_数据库相关

<%
'数据库管理类
class Datas
'备份
public sub Bk()
Set fso=server.createobject("scripting.filesystemobject")
fso.CopyFile Server.MapPath(SiteDataPath),Server.MapPath(SiteDataBakPath)
set fso=nothing
response.Write("")
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("")
else
response.Write("")
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("")
else
response.Write("")
end if
end sub
end class
%>

...............................................................................

call CompressData()
     Call BackData()
    
Sub CompressData()
     If Not IsObject(Conn) Then
         CheckData Conn,GetConnstr
     End If
     Set Conn = Nothing
     Dim DBPath
     DBPath = Server.MapPath(Request.Form("Data_Path"))
     Dim BoolIs97
     BoolIs97 = Request.Form("boolIs97")
     CompactDB DBPath,boolIs97
End Sub


'=====================压缩参数=========================
Sub CompactDB(DBPath, boolIs97)
     On Error Resume Next
     Dim Fso, Engine, strDBPath,JET_3X
     strDBPath = Left(DBPath,InstrRev(DBPath,"\"))
     Set Fso = CreateObject("Scripting.FileSystemObject")
     If Err.Number <> 0 Then
         Err.Clear()
     response.write "当前站点可能不支持FSO组件,压缩操作跳过。"
         Exit Sub
     End If
     If Fso.FileExists(DBPath) Then
             Fso.CopyFile DBPath,strDBPath & "CompactDBTemp.mdb"
             Set Engine = CreateObject("JRO.JetEngine")
             If BoolIs97 = "True" Then
                 Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "CompactDBTemp.mdb", _
                 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "CompactDBTemp1.mdb;" _
                 & "Jet OLEDB:Engine Type=" & JET_3X
             Else
                 Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "CompactDBTemp.mdb", _
                 "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "CompactDBTemp1.mdb"
             End If
         Fso.CopyFile strDBPath & "CompactDBTemp1.mdb",DBPath
         Fso.DeleteFile(strDBPath & "CompactDBTemp.mdb")
         Fso.DeleteFile(strDBPath & "CompactDBTemp1.mdb")
         Set Fso = nothing
         Set Engine = nothing
         If Err.Number <> 0 Then
             Err.Clear()
             response.write "出错原因" & Err.Description & "操作,压缩操作跳过。"
             Exit Sub
         End If
     response.write "你的数据库, " & Replace(DBPath,"\","\\") & ", 已经压缩成功!"
     Else
         response.write "数据库名称或路径不正确. 请重试!"
     End If
End Sub

Sub BackData()
     If Not IsObject(Conn) Then
         CheckData Conn,GetConnstr
     End If
     Dim DBPath
     Dim BackDBPath,Fso
     BackDBPath = ""
     DBPath = Server.MapPath(Request.Form("Data_Path"))
     BackDBPath = BackDBPath & year(now) & "_" & month(now) & "_" & day(now) & "_" &   hour(now)   & "_" &   minute(now) &".mdb"
     BackDBPath = Server.MapPath(BackDBPath)
     On Error Resume Next
     Set Fso = Server.createobject("scripting.filesystemobject")
     If Err.Number <> 0 Then
         Err.Clear()
         response.write "出错原因" & Err.Description & ",当前站点可能不支持FSO组件,备份操作跳过。"
         Exit Sub
     End If
     If Fso.Fileexists(DBPath) then
         Fso.Copyfile DBPath,BackDBPath
         response.write"备份数据库成功,您备份的数据库路径为:" & Replace(BackDBPath,"\","\\")
     Else
         response.write "找不到您所需要备份的文件。"
     End if
     If Err.Number <> 0 Then
         Err.Clear()
         response.write "出错原因" & Err.Description & "操作,备份操作跳过。"
         Exit Sub
     End If
     Set Fso = Nothing
End Sub


上一篇: asp导出excel并打印报表(
下一篇: 用ASP实现在线压缩与解压缩
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags:
相关日志:
评论: 0 | 引用: 0 | 查看次数: 4216
发表评论
昵 称:
密 码: 游客发言不需要密码.
邮 箱: 邮件地址支持Gravatar头像,邮箱地址不会公开.
网 址: 输入网址便于回访.
内 容:
验证码:
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 300 字 | UBB代码 开启 | [img]标签 关闭