private void btnBrowse_Click(object sender, EventArgs e) { DBEngineChooserDialog dialog = new DBEngineChooserDialog(Container); dialog.ShowDialog(this); if (dialog.DialogResult == DialogResult.OK) { if (dialog.SelectedItems != null) { ChooserControlItem selectedItem = dialog.SelectedItem as ChooserControlItem; if ((selectedItem == null) || (selectedItem.Item == null)) { } else { EnterpriseManagementObject item = selectedItem.Item as EnterpriseManagementObject; if (!string.IsNullOrEmpty(item.FullName)) { if (item.DisplayName.ToLower() == "MSSQLServer".ToLower() || item.DisplayName.ToLower() == "SQLEXPRESS".ToLower()) { txtInstanceName.Text = item.Path; } else { txtInstanceName.Text = item.Path + "\\" + item.DisplayName; } using (ManageQueryOleDBSDKHelper helper = new ManageQueryOleDBSDKHelper(ManagementGroup)) { switch (item.GetClasses()[0].Name) { case "Microsoft.SQLServer.DBEngine": Databases = helper.GetRelatedObjects(item.Id, "Microsoft.SQLServer.Library", "Microsoft.SQLServer.Database"); break; case "Microsoft.SQLServer.2014.DBEngine": Databases = helper.GetRelatedObjects(item.Id, "Microsoft.SQLServer.2014.Discovery", "Microsoft.SQLServer.2014.Database"); break; case "Microsoft.SQLServer.2016.DBEngine": Databases = helper.GetRelatedObjects(item.Id, "Microsoft.SQLServer.2016.Discovery", "Microsoft.SQLServer.2016.Database"); break; default: break; } cmbDatabase.DataSource = new BindingSource(Databases, null); cmbDatabase.DisplayMember = "DisplayName"; cmbDatabase.ValueMember = "Id"; ManagementPackClass winClass = helper.GetManagementPackClass("Microsoft.Windows.Library", "Microsoft.Windows.Computer"); principalName = helper.GetObjectsByName(item.Path, winClass).FirstOrDefault().DisplayName; } } } } } }