views:

43

answers:

3

How can I get’s all database’s name that created in sql server in local system. thanks..

+5  A: 

The following SQL command will get you all of the names of the databases on the server where it is executed. To see more information, change name to *.

SELECT name
  FROM sys.databases
Ardman
+2  A: 

The most platform-independent way would be to query the information_schema. SQL Server also offers a range of system tables / views which can be used for the same purpose; they offer more information (especially SQL Server specific), but they aren't portable, not even across different versions of SQL Server.

tdammers
+1  A: 

Here is the code (you may want to check for the details from here: http://dataconnectionsuite.codeplex.com/SourceControl/changeset/view/57274#1206522)

        try
        {
            this.databasesComboBox.Items.Clear();
            this.databasesComboBox.Items.Add("Please wait while loading available databases...");
            DataTable tables = new DataTable("Tables");
            using (IDbConnection connection = this.GetConnection())
            {
                IDbCommand command = connection.CreateCommand();
                command.CommandText = "SELECT * FROM sys.Databases";
                connection.Open();
                tables.Load(command.ExecuteReader(CommandBehavior.CloseConnection));
            }
            this.databasesComboBox.Items.Clear();
            foreach (DataRow row in tables.Rows)
                this.databasesComboBox.Items.Add(row[0].ToString());
        }
        catch (SqlException)
        {
            this.databasesComboBox.Items.Clear();
            this.databasesComboBox.Items.Add("Connection error. Check server & credentials");
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error while loading available databases: " + ex.ToString());
        }
        finally
        {
            DatabaseListCreating = false;
        }
Pierre 303
thanks ...it solved.
na.fa
You are welcome
Pierre 303