1
votes

I'm working on a asp-classic vbscript website and am curious if there is a way to display the tables in a database. I have looked online and saw some examples but they don't explain what to actually do with the code. I am VERY new so if someone could make this make sense for me that would be awesome.

DBMS: Microsoft SQL Server

2
What DBMS do you use? - Ekkehard.Horner
Microsoft SQL Server @Ekkehard.Horner - user3199543

2 Answers

2
votes
Set Cat = CreateObject("ADOX.Catalog")
Cat.ActiveConnection = "Provider=sqloledb;Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;"
For Each Table In Cat.Tables
    WScript.Echo Table.Name
Next
1
votes

To get you started:

  Const adSchemaTables =         20 ' 00000014

  Dim sCS : sCS     = "...your connection string..."
  Dim oDb : Set oDb = CreateObject("ADODB.CONNECTION")
  oDb.Open sCS
  Dim oRs : Set oRs = oDb.OpenSchema(adSchemaTables)
  Do Until oRs.EOF
     If oRs("TABLE_TYPE") = "TABLE" Then WScript.Echo oRs("TABLE_NAME")
     oRs.MoveNext
  Loop

[If you really don't know about connectionstrings, look here.