Enumerate Database Names


Author
Message
Kent Meyer
Kent Meyer
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 5, Visits: 8
How do I get a list of Databases available on a Server?
Kent Meyer
Kent Meyer
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 5, Visits: 8

Here is one way....

 

SqlConnectionStringBuilder cnStr = new SqlConnectionStringBuilder();

cnStr.UserID = this.txtUsername.Text;

cnStr.Password = this.txtPassword.Text;

cnStr.DataSource = this.cboSQLServer.Text;

cnStr.ConnectTimeout = 30;

SqlConnection cn = new SqlConnection();

cn.ConnectionString = cnStr.ConnectionString;

cn.Open();

System.Data.DataTable dbList = cn.GetSchema("Databases");

foreach (System.Data.DataRow row in dbList.Rows)

{

this.cboDatabase.Items.Add(row[0]);

}


StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Yes, the GetSchema() is probably the preferred way to do it.  You can also look at the sys.sysobjects view and I think there is a sys.sysdatabases view, but using GetSchema() is version independent.  Also, if you call GetSchema() and don't pass it any restrictions, it will give you a DataTable containing the different schema objects that can be queried and the restrictions that are needed to narrow each of the selections.
Kent Meyer
Kent Meyer
StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)StrataFrame Beginner (5 reputation)
Group: Forum Members
Posts: 5, Visits: 8
I was just wondering if there was a way do do this using the Strataframe connection manager...
StrataFrame Team
S
StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)StrataFrame Developer (4.6K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Ah, the ConnectionManager uses the GetSchema() method internally, but I don't believe that the method is exposed to enumerate the databases.  We have a background worker thread that gathers the available databases when the you click the drop-down for the database selection.
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search