List all running databases

I am writing a small database administration program. It works fine if you give db, but not when you don't know which db is installed.

How can I list all running databases?

eg. Program Output:

  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
+3
source share
4 answers

To list the instances of the sql server (what you think you think) you can find various examples of how to do this that rely on the Sql Server Browser server service, otherwise SQLDMO is used.

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 you are looking for more than that, i.e. can detect ect mysql / oracle. over a network, a more general tool, such as nmap , may be more suitable.

+4
source

You will need to query all known database ports to see if there is a running instance. If the database runs on a non-standard port, you probably cannot find it.

+2
source

For SQL Server, you can simply execute the procedure

 exec SP_HelpDB 

Note that this will only display all the databases on the server that you have access to.

If you want all the databases to be independent of your access, you can do this:

 SELECT NAME FROM master..sysdatabases 
0
source

This is a repeated hash of the previous poster response, but in VB.

You want to use the Sql.SqlDataSourceEnumerator.Instance.GetDataSources method of the System.Data.Sql class.

 Imports System.Data.Sql Module Module1 Sub Main() ' Retrieve the enumerator instance and then the data. Dim instance As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance Dim table As System.Data.DataTable = instance.GetDataSources() ' Display the contents of the table. DisplayData(table) Console.WriteLine("Press any key to continue.") Console.ReadKey() End Sub Private Sub DisplayData(ByVal table As DataTable) For Each row As DataRow In table.Rows For Each col As DataColumn In table.Columns Console.WriteLine("{0} = {1}", col.ColumnName, row(col)) Next Console.WriteLine("============================") Next End Sub End Module 

I have a database configuration dialog that uses this. Works like a champion.

0
source

All Articles