how to get table names of a database from an ado connection string

I want to get the entire details of a database from an ado connection string. Like table name, field names,
queries etc. I am getting the data base name from the connection string. But i want to get the table names from it without using a dao reference.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

jetforceConnect With a Mentor Commented:
Sorry TimCottee,
 but when I posted the answer, there was no reply, if you look at the times of the two posts. They are only a minute apart. It took me more than a minute to write the answer. It was just coincidince in my choice of wording.
If pratheesh wants to reject my answer and award the points
to ryancys, that is fine.
Ryan ChongCommented:
Hi pratheesh,

Retreive ALL the information about Access Table & Fields using ADO:

'Hope will help.
There is two ways, the first is using ADOX, you need to select the reference. This really only works well from Access Databases.
 The second is using the open schema method from the Connection object. The method/function returns a recordset.

The following returns all the tables for a connection, you can change it retrieve views/queries as well.
 Set recScheme = connDB.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))

This will return all the fields for a table

Set recTable = connDB.OpenSchema(adSchemaColumns, Array(Empty, Empty, Trim$(recScheme("Table_Name"))))

Hope this helps, you can find more about this function in the MSDN Help files.

Never miss a deadline with

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Jetforce, you are not new to EE so should be aware of the guidelines on comments vs answers. Please re-read this at the bottom of this page and do not post "answers" in this way in future. If you continue to do so your account will be referred to customer services.

If you have opened the connection the following example shows how you can obtain the table names and table types from the database. In this case an access database but that is only limited by your connection string properties so if you are using SQL Server then the appropriate connection string would give you the same sort of results.

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strMessage As String
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\cremosa2k.mdb;"
Set rst = cnn.OpenSchema(adSchemaTables)
With rst
    strMessage = strMessage & rst.Fields("TABLE_NAME").Value & " : " & rst.Fields("TABLE_TYPE").Value & vbLf
  Loop Until .EOF
End With
MsgBox strMessage
Set rst = Nothing
Set cnn = Nothing

Hi jetforce,

I'm rejecting your answer as it duplicates the information posted by ryancys.

>but when I posted the answer, there was no reply, if you look at the times of the two posts.

This is one of the reasons why it is the etiquette here in VB to *always* post comments.  This topic area is very busy, and it is not unusual to see three or four nearly simultaneous comments all with the correct answer.

Friendly Neighbourhood Community Support Moderator
pratheeshAuthor Commented:
thanks jetforce for your immediate action
All Courses

From novice to tech pro — start learning today.