private void RefreshColumnList(TreeNode nd) { nd.Text += " (expanding...)"; Application.DoEvents(); this.BeginUpdate(); this.UseWaitCursor = true; rsDbSql dbConn = this.GetDbObject(nd); try { nd.Nodes.Clear(); foreach (ColumnParams cp in dbConn.GetColumns(nd.Parent.Parent.Parent.Text, nd.Parent.Text, (SqlObjType)nd.Parent.Tag == SqlObjType.View)) { TreeNode ndCol = new TreeNode(cp.ToString()); ndCol.Name = string.Format("{0}.{1}.{2}", nd.Parent.Parent.Parent.Text, nd.Parent.Text, cp.ColumnName); ndCol.Tag = SqlObjType.Column; ndCol.ImageKey = ndCol.SelectedImageKey = "Column"; nd.Nodes.Add(ndCol); } } catch (Exception ex) { MessageBox.Show(this, string.Format("Unable to retreive the list of columns from the SQL server:\n\n{0}\n\nApplication Version: {1}", ex.Message, Application.ProductVersion), "Error"); nd.Nodes.Clear(); nd.Nodes.Add("<EMPTY>"); nd.Collapse(false); } finally { nd.Text = nd.Text.Substring(0, nd.Text.LastIndexOf('(')).TrimEnd(); this.EndUpdate(); this.UseWaitCursor = false; } }
private void DoSearch(string srchValue, bool incCols) { this.UseWaitCursor = true; this.lstSearchResults.BeginUpdate(); this.lstSearchResults.Items.Clear(); this.lstSearchResults.ShowGroups = true; try { rsDbSql dbConn = this.GetDbObject(this._sqlExplorer.SelectedNode); bool noResults = true; foreach (string tbl in dbConn.SearchForTable(srchValue, true)) { this.lstSearchResults.Items.Add(new ListViewItem(tbl, 2, this.lstSearchResults.Groups["grpTables"])); noResults = false; } foreach (string view in dbConn.SearchForView(srchValue, true)) { this.lstSearchResults.Items.Add(new ListViewItem(view, 8, this.lstSearchResults.Groups["grpViews"])); noResults = false; } foreach (string sp in dbConn.SearchForStoredProceedure(srchValue, true)) { this.lstSearchResults.Items.Add(new ListViewItem(sp, 4, this.lstSearchResults.Groups["grpStoredProcs"])); noResults = false; } foreach (string func in dbConn.SearchForFunction(srchValue, true)) { this.lstSearchResults.Items.Add(new ListViewItem(func, 4, this.lstSearchResults.Groups["grpFuncs"])); noResults = false; } try { if (incCols) { try { foreach (string dbNm in dbConn.GetDatabaseList()) { try { foreach (string tbl in dbConn.GetTableList(dbNm)) { try { foreach (ColumnParams cp in dbConn.GetColumns(dbNm, tbl)) { try { if (cp.ColumnName.Contains(srchValue)) { this.lstSearchResults.Items.Add(new ListViewItem(string.Format("{0}.{1}.{2} ({3})", dbNm, tbl, cp.ColumnName, cp.DataType.ToString()), 5, this.lstSearchResults.Groups["grpCols"])); noResults = false; } } catch (Exception ex) { if (ex.InnerException is System.Data.SqlClient.SqlException && ex.ToString().Contains("The server principal ") && ex.ToString().Contains(" is not able to access the database ") && ex.ToString().Contains(" under the current security context.")) { // We're going to ignore this error and continue // searching whichever databases we *are* // allowed to access. } else { throw; } } } } catch (Exception ex) { if (ex.InnerException is System.Data.SqlClient.SqlException && ex.ToString().Contains("The server principal ") && ex.ToString().Contains(" is not able to access the database ") && ex.ToString().Contains(" under the current security context.")) { // We're going to ignore this error and continue // searching whichever databases we *are* // allowed to access. } else { throw; } } } } catch (Exception ex) { if (ex.InnerException is System.Data.SqlClient.SqlException && ex.ToString().Contains("The server principal ") && ex.ToString().Contains(" is not able to access the database ") && ex.ToString().Contains(" under the current security context.")) { // We're going to ignore this error and continue // searching whichever databases we *are* // allowed to access. } else { throw; } } } } catch (Exception ex) { if (ex.InnerException is System.Data.SqlClient.SqlException && ex.ToString().Contains("The server principal ") && ex.ToString().Contains(" is not able to access the database ") && ex.ToString().Contains(" under the current security context.")) { // We're going to ignore this error and continue // searching whichever databases we *are* // allowed to access. } else { throw; } } } } catch (Exception ex) { MessageBox.Show(this, "Unexpected Error", "An error occured while trying to search for the specified column:\n" + ex.Message); } // If nothing got added, we'll just add an entry informing the user // that no objects matching their search were found. if (noResults) { this.lstSearchResults.ShowGroups = false; this.lstSearchResults.Items.Add(new ListViewItem("No matches found...")); } this.splitContainer1.Panel2Collapsed = false; this.txtSearch.Text = string.Empty; } catch (Exception ex) { #if DEBUG MessageBox.Show(this, "An error occured while trying to perform the search:\n\n" + ex.ToString() + "\n\nApplication Version: " + Application.ProductVersion, "Error"); #else MessageBox.Show(this, "An error occured while trying to perform the search:\n\n" + ex.Message + "\n\nApplication Version: " + Application.ProductVersion, "Error"); #endif } finally { this.lstSearchResults.EndUpdate(); this.UseWaitCursor = false; } }