Search code examples
.netms-accessms-jet-ace

opening an mdb access file without access


i dont have microsoft access but would like to open an mdb file, is there any way to do this?

the mdb file contains SQL code that i need. it is just a file that connects to a remote database. i need to view the sql code

i did try openoffice base, but it only showed me some tables. i dont see where the sql code is?


Solution

  • This VBScript will print out the SQL statements from the saved queries in your MDB database.

    Option Explicit
    Dim dbe
    Dim db
    Dim qdf
    
    Set dbe = CreateObject("DAO.DBEngine.36")
    'change the next line to include the full path to your database
    Set db = dbe.OpenDatabase("C:\SomeFolder\YourDatabase.mdb")
    For Each qdf In db.QueryDefs
        If Left(qdf.Name,1) <> "~" Then
            Wscript.StdOut.WriteLine qdf.Name
            Wscript.StdOut.WriteLine qdf.SQL
            Wscript.StdOut.WriteLine String(20, "-")
        End If
    Next
    Set db = Nothing
    Set dbe = Nothing
    

    I saved it as DumpQuerySQL.vbs, then ran it from a command prompt like this:

    cscript DumpQuerySQL.vbs > querySQL.txt