Ejemplo n.º 1
0
        //***************************************************************************
        // Private Methods
        //
        private void PopulateTableList()
        {
            this.lstSrcTables.BeginUpdate();
            this.lstSrcTables.Items.Clear();
            try
            {
                if (this._db.GetType().Name != "rsDbSql")
                {
                    throw new Exception("Export wizrd currently only support SQL database sources.");
                }

                rsDbSql  db   = (rsDbSql)this._db;
                string[] tbls = db.GetTableList(this._dbNm);
                for (int i = 0; i < tbls.Length; i++)
                {
                    this.lstSrcTables.Items.Add("T: " + tbls[i]);
                }

                string[] vws = db.GetViewList(this._dbNm);
                for (int i = 0; i < vws.Length; i++)
                {
                    this.lstSrcTables.Items.Add("V: " + vws[i]);
                }
            }
            catch (Exception ex)
            {
                CrossThreadUI.ShowMessageBox(this, "Unable to retrieve table names: " + ex.Message, "Unexpected Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                this.Dispose();
            }
            finally
            {
                this.lstSrcTables.EndUpdate();
            }
        }
Ejemplo n.º 2
0
        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;
            }
        }
Ejemplo n.º 3
0
        private void RefreshTableList(TreeNode nd)
        {
            nd.Text += " (expanding...)";
            Application.DoEvents();
            this.BeginUpdate();
            this.UseWaitCursor = true;
            rsDbSql dbConn = this.GetDbObject(nd);

            try
            {
                nd.Nodes.Clear();
                string[] objList = null;
                if ((SqlObjType)nd.Tag == SqlObjType.TableGroup)
                {
                    objList = dbConn.GetTableList(nd.Parent.Text);
                }
                else
                {
                    objList = dbConn.GetViewList(nd.Parent.Text);
                }
                foreach (string tbl in objList)
                {
                    TreeNode ndTbl = new TreeNode(tbl);
                    ndTbl.Name = string.Format("{0}.{1}", nd.Parent.Text, tbl);
                    if ((SqlObjType)nd.Tag == SqlObjType.TableGroup)
                    {
                        ndTbl.Tag = SqlObjType.Table;
                        ndTbl.ContextMenuStrip = this.mnuNdScript;
                    }
                    else
                    {
                        ndTbl.Tag = SqlObjType.View;
                        ndTbl.ContextMenuStrip = this.mnuNdObj;
                    }
                    ndTbl.ImageIndex         = ((SqlObjType)ndTbl.Tag == SqlObjType.Table) ? 2 : 8;
                    ndTbl.SelectedImageIndex = ((SqlObjType)ndTbl.Tag == SqlObjType.Table) ? 2 : 8;
                    ndTbl.ImageKey           = ndTbl.SelectedImageKey = ((SqlObjType)ndTbl.Tag).ToString(); // == SqlObjType.Table) ? "Table" : "StoredProc";
                    TreeNode ndColumns = new TreeNode("Columns");
                    ndColumns.Nodes.Add("<EMPTY>");
                    ndColumns.Tag = SqlObjType.ColumnGroup;
                    ndColumns.ContextMenuStrip = this.mnuNdGroup;
                    ndTbl.Nodes.Add(ndColumns);
                    if ((SqlObjType)ndTbl.Tag == SqlObjType.Table)
                    {
                        TreeNode ndKeys = new TreeNode("Keys");
                        ndKeys.Nodes.Add("<EMPTY>");
                        ndKeys.Tag = SqlObjType.KeyGroup;
                        ndKeys.ContextMenuStrip = this.mnuNdGroup;
                        ndTbl.Nodes.Add(ndKeys);
                        TreeNode ndConstraints = new TreeNode("Constraints");
                        ndConstraints.Nodes.Add("<EMPTY>");
                        ndConstraints.Tag = SqlObjType.ConstraintGroup;
                        ndConstraints.ContextMenuStrip = this.mnuNdGroup;
                        ndTbl.Nodes.Add(ndConstraints);
                    }
                    TreeNode ndTriggers = new TreeNode("Triggers");
                    ndTriggers.Nodes.Add("<EMPTY>");
                    ndTriggers.Tag = SqlObjType.TriggerGroup;
                    ndTriggers.ContextMenuStrip = this.mnuNdGroup;
                    ndTbl.Nodes.Add(ndTriggers);
                    TreeNode ndIndexes = new TreeNode("Indexes");
                    ndIndexes.Nodes.Add("<EMPTY>");
                    ndIndexes.Tag = SqlObjType.IndexGroup;
                    ndIndexes.ContextMenuStrip = this.mnuNdGroup;
                    ndTbl.Nodes.Add(ndIndexes);
                    nd.Nodes.Add(ndTbl);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, string.Format("Unable to retreive the list of tables 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;
            }
        }