Richard's profileRichard Siddaway's BlogPhotosBlogLists Tools Help

Blog


    February 03

    View Access table definitions

    We’ve looked quite a bit at how we can work with Access databases but how do we investigate the structure of the database.  The first thing we need to know is the tables in our database

    001
    002
    003
    004
    005
    006
    007
    008
    009
    010
    011
    012
    013
    014
    015
    016
    017
    018
    function Get-AccessTableDefinition {
    param (
        [string]$name,
        [string]$path
    )
        $file = Join-Path -Path $path -ChildPath $name 
        if (!(Test-Path $file)){Throw "File Does Not Exists"}

        $conn = New-Object -ComObject ADODB.Connection
        $conn.Open("Provider = Microsoft.JET.OLEDB.4.0; Data Source = $file")
        $cat = New-Object -ComObject ADOX.Catalog
        $cat.ActiveConnection = $conn

    ## view tables
    ## note user tables are of type TABLE
        $cat.tables | select Name, DateCreated, DateModified
        $conn.Close()
    }

     

    The first part of the function tests that the file exists – we’ve seen this before when opening databases. Previous functions have mainly relied on SQL and ADO.NET capability.  In this case we are using ADO (the older brother of ADO.NET). We need to create a COM object for the connection and open it using the path to our database.  This will fail if we already have the database open!!  We will see how to cope with this later.  We then need to create a ADO Active X catalog representing the database. From that we can list our tables. This list includes the system and user tables.

    N

    Technorati Tags: ,,

    ext stages are to put in some error handling and decide how we will display the structure of an individual table.

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    Richard Siddaway has turned off comments on this page.

    Trackbacks

    The trackback URL for this entry is:
    http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!2742.trak
    Weblogs that reference this entry
    • None