asp Access数据备份,还原,压缩类代码_数据库相关
作者:wang 日期:2010-05-19
<%
'数据库管理类
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
'数据库管理类
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 "
Exit Sub
End If
response.write "
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
评论: 0 | 引用: 0 | 查看次数: 4164
发表评论