internal void SetConnection() { try { this.ddDatabase.Items.Clear(); ConnectionData connData = new ConnectionData(); connData.SQLServerName = this.ddServers.Text; connData.UserId = this.txtUser.Text; connData.Password = this.txtPassword.Text; connData.AuthenticationType = this.AuthenticationType; connData.ScriptTimeout = 10; bool hasError; this.databaseList = InfoHelper.GetDatabaseList(connData, out hasError); if (hasError) { MessageBox.Show("Unable to connect to specified SQL Server.\r\nPlease select another server.", "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); if (this.ServersEnumerated != null) { this.ServersEnumerated(this, new ServersEnumeratedEventArgs(new string[0], "Connection error. Please re-select.")); } this.Cursor = Cursors.Default; return; } for (int i = 0; i < databaseList.Count; i++) { this.ddDatabase.Items.Add(databaseList[i].DatabaseName); } if (ddDatabase.Visible) { this.ddDatabase.Sorted = true; if (this.ddDatabase.Items.Count > 0) { this.ddDatabase.SelectedIndex = 0; this.ddDatabase.Enabled = true; } else { this.ddDatabase.Enabled = false; this.ddDatabase.Text = "<No databases found>"; } } if (this.ServerConnected != null) { UtilityHelper.UpdateRecentServerList(this.ddServers.Text, this.txtUser.Text, this.txtPassword.Text, this.AuthenticationType); this.ServerConnected(this, new ServerConnectedEventArgs(true, this.AuthenticationType)); } this.Cursor = Cursors.Default; } catch (Exception err) { this.Cursor = Cursors.Default; MessageBox.Show(err.Message, "Error"); } }
private void bgLoadCfg_DoWork(object sender, DoWorkEventArgs e) { List <ServerData> svrDataList = new List <ServerData>(); MultiDbData data = null; BackgroundWorker bg = (BackgroundWorker)sender; if (e.Argument is string) { bg.ReportProgress(-10, "Initializing"); string fileName = e.Argument.ToString(); bg.ReportProgress(10, "Loading " + Path.GetFileName(fileName) + "..."); data = MultiDbHelper.DeserializeMultiDbConfiguration(fileName); if (data == null) //maybe have a flat .cfg file?? { data = MultiDbHelper.ImportMultiDbTextConfig(fileName); } } else if (e.Argument is MultiDbData) { data = (MultiDbData)e.Argument; } if (data != null) { bg.ReportProgress(0, "Applying configuration... "); foreach (ServerData srv in data) { //We need to get the list of databases for this server if it doesn't match the current connection if (srv.ServerName != this.server) { bg.ReportProgress(10, "Retrieving database list from " + srv.ServerName); ConnectionData tmpC = new ConnectionData(); tmpC.Fill(this.connData); tmpC.SQLServerName = srv.ServerName; tmpC.DatabaseName = "master"; srv.Databases = InfoHelper.GetDatabaseList(tmpC); } else { srv.Databases = this.databaseList; } svrDataList.Add(srv); } e.Result = svrDataList; } }
private void SetDatabaseList(string server, string targetDb) { this.databaseList = InfoHelper.GetDatabaseList(new ConnectionData(server, "")); this.ddDatabase.Items.Clear(); for (int i = 0; i < this.databaseList.Count; i++) { if (!this.databaseList[i].IsManuallyEntered) { this.ddDatabase.Items.Add(this.databaseList[i].DatabaseName); } } for (int i = 0; i < this.ddDatabase.Items.Count; i++) { if (this.ddDatabase.Items[i].ToString().ToLower() == targetDb.ToLower()) { this.ddDatabase.SelectedIndex = i; } } }