Microsoft KB Archive/249718: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
 
Line 47: Line 47:
== SUMMARY ==
== 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.
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.


</div>
</div>
Line 66: Line 66:
#DEFINE adSchemaTables 20
#DEFINE adSchemaTables 20


cn = CREATEOBJECT(&quot;ADODB.Connection&quot;)
cn = CREATEOBJECT("ADODB.Connection")
rsTable = CREATEOBJECT(&quot;ADODB.Recordset&quot;)
rsTable = CREATEOBJECT("ADODB.Recordset")


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


WITH cn
WITH cn
Line 85: Line 85:
   rsTable = .OpenSchema(adSchemaTables)
   rsTable = .OpenSchema(adSchemaTables)
   DO WHILE NOT rsTable.EOF
   DO WHILE NOT rsTable.EOF
       ? rsTable.FIELDS(&quot;TABLE_NAME&quot;).VALUE
       ? rsTable.FIELDS("TABLE_NAME").VALUE
       rsTable.MoveNext
       rsTable.MoveNext
   ENDDO
   ENDDO

Latest revision as of 13:52, 21 July 2020

Knowledge Base


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

Article ID: 249718

Article Last Modified on 7/13/2004



APPLIES TO

  • Microsoft ActiveX Data Objects 2.5
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition



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.


Additional query words: ADO OpenSchema adSchemaTables schema container

Keywords: kbhowto kbcodesnippet kbdatabase KB249718