Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    Posts
    8

    Question Unanswered: compactdatabase function and secured mdb

    hi all,

    amazed at how difficult it is to find this info. i have an access 2000 mdb on a web server. i need to be able to compact the database remotely. using a combination of asp and vbscript, i know how to do this for a non-secured access database. however, i've been unable to locate any documentation on how to use compactdatabase with a secured mdb with a mdw file. can anyone help?

    here's the code i have for compacting a regular non-secured mdb. thanks in advance for any help.

    glenn

    '******************************************

    function fileExists ( filepath )
    fileExists = objFSO.FileExists ( filepath )
    end function

    function fileDelete ( filepath )
    fileDelete = objFSO.DeleteFile ( filepath )
    end function

    ' Dim our variables
    Dim objJet
    Dim objFSO
    Dim f
    Dim f_New

    ' Assign values for source and destination
    f = Server.MapPath("databasename.mdb")
    f_New = Server.MapPath("newdatabasename.mdb")

    Set objJet = Server.CreateObject ("JRO.JetEngine")
    Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")

    ' Make sure there isn't already a file with the
    'name of the compacted database.
    If fileExists ( f_New ) Then
    fileDelete ( f_New )
    End If

    ' Compact the database into the destination location
    objJet.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0; " &_
    "Data Source=" & f & ";", _
    "Provider=Microsoft.Jet.OLEDB.4.0; " &_
    "Data Source=" & f_New & ";"

    ' Delete the original database
    fileDelete ( f )

    'Rename the file back to the original name
    objFSO.MoveFile f_New, f

    'Clean-up
    Set objFSO = Nothing
    Set objJet = Nothing

  2. #2
    Join Date
    Sep 2002
    Posts
    8

    Smile

    well, finally found my answer. for the record, here it is. the additional parameters i was looking for were appropriately enough, "User ID", "Password" and "Jet OLEDBystem Database"


    function fileExists ( filepath )
    fileExists = objFSO.FileExists ( filepath )
    end function

    function fileDelete ( filepath )
    fileDelete = objFSO.DeleteFile ( filepath )
    end function

    Dim objJet
    Dim objFSO
    Dim f
    dim s
    Dim f_New

    ' Assign values for source and destination
    f = Server.MapPath("databasename.mdb")
    f_New = Server.MapPath("compactedDB.mdb")
    s = Server.MapPath("workgroupfilename.mdw")

    ' Object instantiation
    Set objJet = Server.CreateObject ("JRO.JetEngine")
    Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")

    ' Make sure there isn't already a file with the
    'name of the compacted database.
    If fileExists ( f_New ) Then
    fileDelete ( f_New )
    End If

    objJet.CompactDatabase "Provider=Microsoft.Jet.OLEDB.4.0; " &_
    "Data Source=" & f & ";" &_
    "Jet OLEDBystem Database=" & s & ";" &_
    "Jet OLEDB:Encrypt Database=false;" &_
    "User ID=userID;" &_
    "Password=userpassword;", _
    "Provider=Microsoft.Jet.OLEDB.4.0; " &_
    "Data Source=" & f_New & ";"

    ' Delete the original database
    fileDelete ( f )

    'Rename the file back to the original name
    objFSO.MoveFile f_New, f

    'Clean-up
    Set objFSO = Nothing
    Set objJet = Nothing


    works like a charm.

    glenn

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •