Finding tablenames for ODBC-datasource

How do I find the table names and field names for an ODBC DSN? (It must be doavle, Microsoft Query does it).
Who is Participating?
AzraSoundConnect With a Mentor Commented:
Do you need to know the provider?  I thought the original question was in regards to finding out tables and fields given the DSN.  Once you have the DSN, you should be able to connect to any data source as long as the necessary ODBC driver is installed.
Don't know if these will work for you since I think they are tied to SQL Server but these are a few that I use:

List of Tables:
select * from sysobjects where type = 'U'

Stuff I want to know about the fields in a table:
select as 'Table', as 'Field', syscolumns.isnullable, as 'Data Type', syscolumns.length from sysobjects left join syscolumns on = join systypes on syscolumns.xtype = systypes.xtype where = 'MyTable' order by syscolumns.colid

Is this really a .NET question?

MS Query or any other ODBC consumer uses ODBC API calls to get the info you want, see and look at the SQLTables and SQLColumns functions.  

Unless you can make ODBC API calls direct to your DSN that's not much use.  The actual SQL, or other code that is sent to the db depends on the ODBC driver you are using.

I suspect you question is more like, how do I get a list of tables/columns from a .NET app, or a VB app  - or whatever.  In which case it really depends on you DMBS, SQL Server has procedures like sp_catalogs_rowset and the sysobjects or INFORMATION_SCHEMA tables to provide this kind of information.

Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Use the DSN to connect to the database.  Once you have a dataset object, you can capture its Tables property to get a DataTableCollection, iterate through those DataTable objects to get their Columns properties, then grab information on those DataColumns.
AzraSound - how do you create a dataset that contains everything in your database?
Never mind...doesnt do you any good unless you would already know the table names.
Well then I am not aware of any new ways utilizing only .NET.  In prior versions, you could use ADOX to grab this info, sample here:

The code only allows for opening an Access97 or Access2000 DB, but if you look at the code where it sets the connection strings, you can just alter it to point to any DSN and it should work fine.
LlandrAuthor Commented:
The question is actually how do I make an ODBC-native call using .Net.
LlandrAuthor Commented:
AzraSound: ADO is Ok but I dont know how to find the provider from the ODBC source.
LlandrAuthor Commented:
Of course.
The solution became:

Step 1: Add the ADO .NET component as reference

               conn.Open("DSN=" & DSN)

               Dim recSet As ADODB.Recordset

               recSet = conn.OpenSchema(SchemaEnum.adSchemaTables)

               Do While Not recSet.EOF
                    result.Add(recSet.Fields(2).Value, recSet.Fields(2).Value)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.