asp的access数据库管理程序
asp的access数据库管理程序
'备份数据库
sub ad_backupdata()
on error resume next
bkfolder = server.MapPath("../mdbackup/")
bkpath = bkfolder&"\"&year(now)&"-"&month(now)&"-"&day(now)&".asp"
dbpath = Server.MapPath("../mdbdate/company.mdb")
Set Fso=server.createobject("scripting.filesystemobject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
if fso.FileExists(dbpath) then
If fso.FolderExists(bkfolder)=false Then fso.CreateFolder(bkfolder)
fso.copyfile dbpath,bkpath
response.write "备份数据库成功"
Else
response.write "找不到数据库文件"
End if
end if
end sub
'数据库压缩
sub ad_compactdata()
on error resume next
dbpath = Server.MapPath("../mdbdate/company.mdb")
cdpath = server.MapPath("../mdbdate/")&"\temp.mdb"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
If fso.FileExists(dbPath) Then
Set Engine = CreateObject("JRO.JetEngine")
set conn=nothing
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath," Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & cdpath
fso.CopyFile cdpath,dbpath
fso.DeleteFile(cdpath)
Set fso = nothing
Set Engine = nothing
response.write "数据库压缩成功"
Else
response.write "找不到数据库文件"
End If
end if
end sub
'恢复数据库
sub ad_restore()
on error resume next
backname=request.form("backname")
if backname="" then
response.write "请指定的备份文件名"
else
backpath=server.MapPath("../mdbackup/")&"\"&backname
Set Fso=server.createobject("scripting.filesystemobject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
if fso.fileexists(backpath) then
fso.copyfile backpath,Server.MapPath("../mdbdate/company.mdb")
response.write "成功恢复数据库"
else
response.write "找不到指定的备份文件"
end if
end if
end if
end sub
'清理备份数据库
sub ad_deldata()
on error resume next
delpath=server.MapPath("../mdbackup/")
Set Fso=server.createobject("scripting.filesystemobject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
fso.deletefolder(delpath)
if Err <> 0 Then
response.write "清理失败或没找到文件"
else
response.write "成功清理备份数据库"
end if
end if
end sub
sub ad_backupdata()
on error resume next
bkfolder = server.MapPath("../mdbackup/")
bkpath = bkfolder&"\"&year(now)&"-"&month(now)&"-"&day(now)&".asp"
dbpath = Server.MapPath("../mdbdate/company.mdb")
Set Fso=server.createobject("scripting.filesystemobject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
if fso.FileExists(dbpath) then
If fso.FolderExists(bkfolder)=false Then fso.CreateFolder(bkfolder)
fso.copyfile dbpath,bkpath
response.write "备份数据库成功"
Else
response.write "找不到数据库文件"
End if
end if
end sub
'数据库压缩
sub ad_compactdata()
on error resume next
dbpath = Server.MapPath("../mdbdate/company.mdb")
cdpath = server.MapPath("../mdbdate/")&"\temp.mdb"
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
If fso.FileExists(dbPath) Then
Set Engine = CreateObject("JRO.JetEngine")
set conn=nothing
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath," Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & cdpath
fso.CopyFile cdpath,dbpath
fso.DeleteFile(cdpath)
Set fso = nothing
Set Engine = nothing
response.write "数据库压缩成功"
Else
response.write "找不到数据库文件"
End If
end if
end sub
'恢复数据库
sub ad_restore()
on error resume next
backname=request.form("backname")
if backname="" then
response.write "请指定的备份文件名"
else
backpath=server.MapPath("../mdbackup/")&"\"&backname
Set Fso=server.createobject("scripting.filesystemobject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
if fso.fileexists(backpath) then
fso.copyfile backpath,Server.MapPath("../mdbdate/company.mdb")
response.write "成功恢复数据库"
else
response.write "找不到指定的备份文件"
end if
end if
end if
end sub
'清理备份数据库
sub ad_deldata()
on error resume next
delpath=server.MapPath("../mdbackup/")
Set Fso=server.createobject("scripting.filesystemobject")
if Err <> 0 Then
response.write "该空间不支持FSO组件,操作失败"
else
fso.deletefolder(delpath)
if Err <> 0 Then
response.write "清理失败或没找到文件"
else
response.write "成功清理备份数据库"
end if
end if
end sub
转载请注明出处:http://www.cnblogs.com/cloudgamer/
如有任何建议或疑问,欢迎留言讨论。
如果觉得文章不错的话,欢迎点一下右下角的推荐。
程序中包含的js工具库CJL.0.1.min.js,原文在这里。