HOWTO: Use ADO to Determine the Tables Contained in a DBC (249718)



The information in this article applies to:

  • ActiveX Data Objects (ADO) 2.5
  • Microsoft Visual FoxPro for Windows 5.0
  • Microsoft Visual FoxPro for Windows 5.0a
  • Microsoft Visual FoxPro for Windows 6.0

This article was previously published under Q249718

SUMMARY

The ActiveX Data Objects (ADO) Connection object's OpenSchema method allows programmatic access to metadata about various database containers. You can use the OpenSchema method to determine what tables are contained in a Database Container (DBC), as demonstrated in the example in the "More Information" section.

MORE INFORMATION

To use this example, save and then run the following program. Make sure that you modify the connection string to point to the DBC of your choice.

* OpenSchema.prg
* Demonstrates the use of the ADO Connection
* Object's OpenSchema method to examine tables
* in a container. Depending on the provider,
* it can also be used to examine columns,
* indices, stored procedures, etc.

#DEFINE adSchemaTables 20

cn = CREATEOBJECT("ADODB.Connection")
rsTable = CREATEOBJECT("ADODB.Recordset")

* connection string for TESTDATA
* in the current drive and directory - change this
* as appropriate for your application
lcConnStr = "Provider=MSDASQL.1;" + ;
   "Extended Properties=DSN=Visual FoxPro Database;" + ;
   "SourceDB=testdata.dbc;" + ;
   "SourceType=DBC;" + ;
   "Exclusive=No;"  + ;
   "BackgroundFetch=Yes;" + ;
   "Collate=Machine;"

WITH cn
   .ConnectionString = lcConnStr
   .OPEN
   rsTable = .OpenSchema(adSchemaTables)
   DO WHILE NOT rsTable.EOF
      ? rsTable.FIELDS("TABLE_NAME").VALUE
      rsTable.MoveNext
   ENDDO
ENDWITH
				


After you run the program, the tables in the specified DBC should be listed on the Visual FoxPro desktop.

Modification Type:MinorLast Reviewed:7/13/2004
Keywords:kbCodeSnippet kbDatabase kbhowto KB249718