tags:

views:

39

answers:

1

I want to list all SQL server instances and their tables.

I have code that lists all the servers correctly but I cannot seem to get a list of their tables.

        DataTable dataSources = SqlDataSourceEnumerator.Instance.GetDataSources();
        foreach (DataRow row in dataSources.Rows)
        {
            Console.WriteLine("Server Name:" + row["ServerName"]);

            foreach (var item in row.ItemArray)
            {
                Console.WriteLine(" - Item: "+ item);
            }
        }
+1  A: 

You can query what tables are in a db using sys.Tables. See below:

USE YourDBName
GO
SELECT name FROM sys.Tables
GO 
Abe Miessler
That would mean I have to be authenticated on that server to be able to see table names doesn't it?
Chris
authentication is a standard requirement for obtaining data!
Mitch Wheat
Yes that is correct, if you want information about the database you will need to be authenticated. This is a good thing.
Abe Miessler