Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumerate all running databases

I'm writing a little Database administration program. It works fine if you give the db, but not when you don't know which db is installed.

How can I enumerate all running databases?

e.g. Output of the program:

Port xy MS-SQL Server 2005
Port ab Postgre SQL Server 
Port cd MySQL Server
Port ef MS-SQL 2008 Express Server
Port gh Oracle Server
like image 296
Stefan Steiger Avatar asked Aug 03 '26 16:08

Stefan Steiger


1 Answers

For enumerating sql server instances (which is what i think you mean) you can find various examples on how to do this, which rely on the Sql Server Browser service, the other way is using SQLDMO.

from MSDN:

using System.Data.Sql;

class Program
{
  static void Main()
  {
    // Retrieve the enumerator instance and then the data.
    SqlDataSourceEnumerator instance =
      SqlDataSourceEnumerator.Instance;
    System.Data.DataTable table = instance.GetDataSources();

    // Display the contents of the table.
    DisplayData(table);

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
  }

  private static void DisplayData(System.Data.DataTable table)
  {
    foreach (System.Data.DataRow row in table.Rows)
    {
      foreach (System.Data.DataColumn col in table.Columns)
      {
        Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
      }
      Console.WriteLine("============================");
    }
  }
}

If your looking for more then this, i.e. being able to detect mysql/oracle ect. across the network then a more general tool such as nmap may be more appropriate.

like image 85
Nick Kavadias Avatar answered Aug 06 '26 04:08

Nick Kavadias