Solved

Retrieve list of tables within MS Access Database

Posted on 2006-07-09
9
201 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 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

16 Experts available now in Live!

Get 1:1 Help Now