1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

我经常用的一个数据库压缩代码。。acc

本帖由 小叶2005-10-29 发布。版面名称:后端开发

  1. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    HTML:
    <%
    '#########################
    '作用:压缩access数据库(默认是ac2000)
    '日期:2004-12-10
    '最后修改:2005-9-16
    '#########################
    option explicit
    Const JET_3X = 4
    
    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")
    
    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
    fso.CopyFile strDBPath & "temp.mdb",dbpath
    fso.DeleteFile(strDBPath & "temp.mdb")
    Set fso = nothing
    Set Engine = nothing
    CompactDB = "你的数据库, " & dbpath & ", 已经被压缩" & vbCrLf
    Else
    CompactDB = "数据库路径或名称不对,请重试!" & vbCrLf
    End If
    
    End Function
    %>
    <html>
    
    <head>
    <title>压缩数据库</title>
    </head>
    <body>
    
    <h2 align="center">压缩Access数据库</h2>
    <p align="center">
    <form action=compact.asp>
    输入数据库的路径包括文件名.<br><br>
    <input type="text" name="dbpath"><br><br>
    <input type="checkbox" name="boolIs97" value="True">如果是ac97,请选上钩
    <br><i> (默认是ac2000)</i><br><br>
    <input type="submit">
    <form>
    <br><br>
    <%
    Dim dbpath,boolIs97
    dbpath = request("dbpath")
    boolIs97 = request("boolIs97")
    
    If dbpath <> "" Then
    dbpath = server.mappath(dbpath)
    response.write(CompactDB(dbpath,boolIs97))
    End If
    %>
    </p>
    </body>
    
    </html>
     
  2. 爱你一生

    爱你一生 New Member

    注册:
    2005-10-29
    帖子:
    2
    赞:
    0
    不错.谢了.. 
     
  3. wm_chief

    wm_chief New Member

    注册:
    2005-09-05
    帖子:
    17,890
    赞:
    46
    先收藏
     
  4. 老林

    老林 New Member

    注册:
    2005-09-06
    帖子:
    10,580
    赞:
    36
  5. 西子宜

    西子宜 Well-Known Member

    注册:
    2005-09-05
    帖子:
    15,739
    赞:
    62
  6. jcking

    jcking Well-Known Member

    注册:
    2005-08-30
    帖子:
    22,282
    赞:
    70
    多谢了