?
Solved

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

Posted on 2001-07-24
6
Medium Priority
?
476 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 53

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 3

Accepted Solution

by:
jetforce earned 180 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

771 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