您好,登錄后才能下訂單哦!
ASP在線壓縮ACCESS數據庫原理很簡單:利用JRO.JetEngine的壓縮功能建立一個新的數據庫文件,然后把原來的刪掉、替換!既然這樣,壓縮程序只需幾行就ok了!
把下面的代碼保存為**.asp,數據庫文件(db.md)放在相同目錄下,執行asp搞定!
<% oldDB = server.mappath("db.mdb") '更改數據庫地址 newDB = server.mappath("db_new.mdb") '生成臨時文件 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 '刪除臨時文件 FSO.MoveFile newDB, oldDB set FSO = Nothing response.write "OK" %>
下面是一個ASP在線壓縮ACCESS數據庫的封裝函數
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('無法識別數據庫類型.');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('找不到數據庫!\n請檢查數據庫路徑是否輸入錯誤!');history.back();</script>" End If End Function
總結
到此這篇關于ASP在線壓縮access數據庫的方法的文章就介紹到這了,更多相關ASP在線壓縮access數據庫內容請搜索億速云以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持億速云!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。