public static DataTable AnalyzeResults(ApplicationSqlConnection connection)
        {
            using (Dal dal = new Dal(connection))
            {
                // Query the differences
                string sql = "select a.counter, a.occurrence - b.occurrence occurrence, a.occurrence * a.value - b.occurrence * b.value value from " +
                             _beforeTempTableName + " b join " + _afterTempTableName + " a on a.counter = b.counter where a.occurrence != b.occurrence order by counter;";
                DataTable differenceTable = dal.ExecuteQueryOneResultSet(sql);

                try
                {
                    // Drop the temporary tables
                    dal.ExecuteQueryNoResultSets(_dropTables);

                    return(differenceTable);
                }
                catch
                {
                    if (differenceTable != null)
                    {
                        differenceTable.Dispose();
                        differenceTable = null;
                    }
                    throw;
                }
            }
        }
        public static DataTable AnalyzeResults(ApplicationSqlConnection connection)
        {
            using (Dal dal = new Dal(connection))
            {
                // Query the differences
                string sql = "select a.name, a.promised - b.promised promised, a.succeeded - b.succeeded succeeded from " +
                             _beforeTempTableName + " b join " + _afterTempTableName + " a on a.name = b.name where a.succeeded != b.succeeded order by name;";
                DataTable differenceTable = dal.ExecuteQueryOneResultSet(sql);

                try
                {
                    // Drop the temporary tables
                    dal.ExecuteQueryNoResultSets(_dropTables);

                    return(differenceTable);
                }
                catch
                {
                    if (differenceTable != null)
                    {
                        differenceTable.Dispose();
                        differenceTable = null;
                    }
                    throw;
                }
            }
        }
 public static void PostExecute(ApplicationSqlConnection connection)
 {
     using (Dal dal = new Dal(connection))
     {
         // Capture the after data
         dal.ExecuteQueryNoResultSets(_captureAfterData);
     }
 }
Ejemplo n.º 4
0
        public QueryExecutionEngine(ApplicationSqlConnection connection, string sql)
        {
            if (connection == null)
            {
                throw new ArgumentNullException(nameof(connection));
            }

            _sql        = sql ?? string.Empty;
            _connection = connection;
        }
        private void DisconnectDatabase()
        {
            if (_connection != null)
            {
                _connection.Dispose();
                _connection = null;
            }

            disconnectButton.Enabled            = false;
            disconnectToolStripMenuItem.Enabled = false;
        }
        public static void PreExecute(ApplicationSqlConnection connection)
        {
            using (Dal dal = new Dal(connection))
            {
                // Run the before and after scripts once just to make sure they are in the plan cache and don't skew the results
                dal.ExecuteQueryNoResultSets(_captureBeforeData);
                dal.ExecuteQueryNoResultSets(_captureAfterData);

                // Drop the temporary tables
                dal.ExecuteQueryNoResultSets(_dropTables);

                // Capture the before data
                dal.ExecuteQueryNoResultSets(_captureBeforeData);
            }
        }
        public LiveViewOptionsForm(ApplicationSqlConnection connection)
        {
            InitializeComponent();

            _options = VisualizerSettings.Instance.LiveViewOptions;
            if (_options == null)
            {
                _options = new LiveViewOptions();
            }

            if (connection != null)
            {
                _options.Connection = connection;
            }
        }
        private bool ConnectDatabase()
        {
            using (ConnectSqlForm connectForm = new ConnectSqlForm())
            {
                DialogResult result = connectForm.ShowDialog();
                if (result == DialogResult.OK)
                {
                    _connection = connectForm.Connection;
                    SetTraceFlags();
                    UpdateDatabaseContext();

                    disconnectButton.Enabled            = true;
                    disconnectToolStripMenuItem.Enabled = true;
                    return(true);
                }
            }
            return(false);
        }
        private void DatabaseComboBox_DropDown(object sender, EventArgs e)
        {
            try
            {
                List <string> databaseNames = new List <string>();
                _isPopulatingDatabaseDropdown = true;

                using (ApplicationSqlConnection connection = AcquireConnection())
                {
                    using (Dal dal = new Dal(connection))
                    {
                        string sql = @"select name from sys.databases;";
                        using (DataTable databaseNameTable = dal.ExecuteQueryOneResultSet(sql))
                        {
                            foreach (DataRow row in databaseNameTable.Rows)
                            {
                                databaseNames.Add(row["name"] as string);
                            }
                        }
                    }
                }

                string previousDatabaseName = _databaseName;
                databaseNames.Sort();
                this.databaseComboBox.Items.Clear();
                this.databaseComboBox.Items.AddRange(databaseNames.ToArray());

                if (string.IsNullOrEmpty(previousDatabaseName) == false &&
                    databaseNames.Contains(previousDatabaseName))
                {
                    databaseComboBox.Text = previousDatabaseName;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message);
            }
            finally
            {
                _isPopulatingDatabaseDropdown = false;
            }
        }
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.serverNameComboBox.Text))
            {
                return;
            }

            Cursor oldCursor = this.Cursor;

            try
            {
                this.Cursor  = Cursors.WaitCursor;
                this.Enabled = false;
                _connection  = this.AcquireConnection();
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    this,
                    "Error connecting to database: " + ex.Message,
                    "Connection Error",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Error);

                return;
            }
            finally
            {
                this.Enabled = true;
                this.Cursor  = oldCursor;
            }

            ViewerSettings.Instance.AddMostRecentSqlServer(serverNameComboBox.Text);
            ViewerSettings.Instance.Save();
            this.DialogResult = DialogResult.OK;
        }