域名預(yù)訂/競(jìng)價(jià),好“米”不錯(cuò)過(guò)
這篇文章主要介紹了ASP在線壓縮access數(shù)據(jù)庫(kù)的方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
ASP在線壓縮ACCESS數(shù)據(jù)庫(kù)原理很簡(jiǎn)單:利用JRO.JetEngine的壓縮功能建立一個(gè)新的數(shù)據(jù)庫(kù)文件,然后把原來(lái)的刪掉、替換!既然這樣,壓縮程序只需幾行就ok了!
把下面的代碼保存為**.asp,數(shù)據(jù)庫(kù)文件(db.md)放在相同目錄下,執(zhí)行asp搞定!
<%
oldDB = server.mappath("db.mdb") '更改數(shù)據(jù)庫(kù)地址
newDB = server.mappath("db_new.mdb") '生成臨時(shí)文件
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set Engine = Server.CreateObject("JRO.JetEngine")
prov = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
Engine.CompactDatabase prov & OldDB, prov & newDB
set Engine = nothing
FSO.DeleteFile oldDB '刪除臨時(shí)文件
FSO.MoveFile newDB, oldDB
set FSO = Nothing
response.write "OK"
%>
下面是一個(gè)ASP在線壓縮ACCESS數(shù)據(jù)庫(kù)的封裝函數(shù)
Function CompactDB(dbPath, boolIs97)
Dim fso, Engine, strDBPath
strDBPath = left(dbPath,instrrev(DBPath,"\"))
Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(dbPath) Then
Set Engine = CreateObject("JRO.JetEngine")
On Error Resume Next
If boolIs97 = "True" Then
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb;" _
& "Jet OLEDB:Engine Type=" & JET_3X
Else
Engine.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbpath, _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strDBPath & "temp.mdb"
End If
If Err Then
response.write "<script LANGUAGE='javascript'>alert('無(wú)法識(shí)別數(shù)據(jù)庫(kù)類(lèi)型.');history.go(-1);</script>"
response.end
end if
fso.CopyFile strDBPath & "temp.mdb",dbpath
fso.DeleteFile(strDBPath & "temp.mdb")
Set fso = nothing
Set Engine = nothing
CompactDB = "<script>alert('壓縮成功!');javascript:history.go(-1);</script>"
Else
CompactDB = "<script>alert('找不到數(shù)據(jù)庫(kù)!\n請(qǐng)檢查數(shù)據(jù)庫(kù)路徑是否輸入錯(cuò)誤!');history.back();</script>"
End If
End Function
總結(jié)
到此這篇關(guān)于ASP在線壓縮access數(shù)據(jù)庫(kù)的方法的文章就介紹到這了,更多相關(guān)ASP在線壓縮access數(shù)據(jù)庫(kù)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
來(lái)源:腳本之家
鏈接:https://www.jb51.net/article/195613.htm
申請(qǐng)創(chuàng)業(yè)報(bào)道,分享創(chuàng)業(yè)好點(diǎn)子。點(diǎn)擊此處,共同探討創(chuàng)業(yè)新機(jī)遇!