// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Data; using System.Data.SqlClient; class MainClass { public static void Main(string[] args) { SqlConnection con = new SqlConnection("server=ARNEPC2;Integrated Security=SSPI;database=master"); con.Open(); SqlCommand cmd = new SqlCommand("sp_databases", con); cmd.CommandType = CommandType.StoredProcedure; SqlDataReader rdr = cmd.ExecuteReader(); while(rdr.Read()) { string dbnam = (string)rdr[0]; Console.WriteLine("Database=" + dbnam); SqlConnection con2 = new SqlConnection("server=ARNEPC2;Integrated Security=SSPI;database=" + dbnam); con2.Open(); SqlCommand cmd2 = new SqlCommand("sp_tables", con2); cmd2.CommandType = CommandType.StoredProcedure; cmd2.Parameters.Add("@table_type", "'TABLE'"); SqlDataReader rdr2 = cmd2.ExecuteReader(); while(rdr2.Read()) { string tblnam = (string)rdr2[2]; Console.WriteLine(dbnam + " " + tblnam); } con2.Close(); } con.Close(); } }