Solved

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

Posted on 2001-07-24
6
471 Views
Last Modified: 2013-11-23
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.
0
Comment
Question by:pratheesh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 52

Expert Comment

by:Ryan Chong
ID: 6311945
Hi pratheesh,

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

http://www.vbcode.com/asp/showsn.asp?theID=688

'Hope will help.
0
 
LVL 3

Expert Comment

by:jetforce
ID: 6311956
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.


PodgeMaster
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6311965
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;"
cnn.Open
Set rst = cnn.OpenSchema(adSchemaTables)
With rst
  .MoveFirst
  Do
    strMessage = strMessage & rst.Fields("TABLE_NAME").Value & " : " & rst.Fields("TABLE_TYPE").Value & vbLf
    .MoveNext
  Loop Until .EOF
End With
MsgBox strMessage
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing

   
0
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
LVL 3

Accepted Solution

by:
jetforce earned 60 total points
ID: 6312097
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.
Jetforce
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6319429
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.

Lunchy
Friendly Neighbourhood Community Support Moderator
0
 

Author Comment

by:pratheesh
ID: 6321737
thanks jetforce for your immediate action
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

691 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