Solved

Retrieve list of tables within MS Access Database

Posted on 2006-07-09
9
202 Views
Last Modified: 2008-02-01
Hi all

Is there a way using ASP and SQL to retrieve a list of all the tables contained within an MS Access Database?

Also is there another SQL query that will return all of the table fields, without returning any records?

Thanks in advance

Richard
0
Comment
Question by:shaggy_the_sheep
  • 5
  • 4
9 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068581
There are a couple of ways:
A.  Query the system tables: MSysObjects
B.  (Better approach) Is to use the Connection's OpenSchema method.
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068592
Using the OpenSchema method does a schema have to have been specifically defined (or is it defined simply through creating tables, etc.)

A simple example would be great please, as i havent a clue where to start :-)

Cheers

Richard
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 500 total points
ID: 17068604
Consider looking at the one in the MDAC Help :)

Here is a link:
OpenSchema Method Example (VB)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthopenschemax.asp
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068632
Okay ive got this far...

<%

'BeginOpenSchemaVB

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string

Public Sub Main()

    Dim Cnxn
    Dim rstSchema
    Dim strCnxn
       
      Set Cnxn = Server.CreateObject("ADODB.Connection")
      Cnxn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../music/_private/musicfiles.mdb")
      
    Set rstSchema = Cnxn.OpenSchema(adSchemaTables)
   
    Do Until rstSchema.EOF
        Response.Write "Table name: " & _
            rstSchema("TABLE_NAME") & vbCrLf & "Table type: " & rstSchema("TABLE_TYPE") & vbCrLf
        rstSchema.MoveNext
    Loop
   
    ' clean up
    rstSchema.Close
    Cnxn.Close
    Set rstSchema = Nothing
    Set Cnxn = Nothing
    Exit Sub

End Sub
'EndOpenSchemaVB

Main()

%>

But i am getting an error:

Object or provider is not capable of performing requested operation.
/edit/getTable.asp, line 18

Line 18 being: Set rstSchema = Cnxn.OpenSchema(adSchemaTables)

Any ideas?

Thanks

Richard
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068643
Have you declared the constant adSchemaTables ?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068646
Otherwise this is where Option Explicit comes in handy :)
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068647
No i dont think i have declared it...where would i need to insert?

Thanks

Richard
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068661
It is as simple as adding the following at the start of your code:
Const adSchemaTables = 20

Or as a lot of ASP developers do, just add all the ADO constants using the include file ADOVBS.inc.
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068671
Easy when you know how!! :-)

Thanks very much

Richard
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now