コード例 #1
0
        private bool ExecuteSql(string sqlText, SqlTextAdapter adapter, bool useTransaction = true)
        {
            if (CancelPending())
            {
                return(false);
            }

            string[] sqlCommands = sqlText.Split(_delimiter, StringSplitOptions.RemoveEmptyEntries);
            int      count       = 1;
            int      length      = sqlCommands.Length;
            string   statement   = string.Empty;

            SendProgressStart(sqlCommands.Length);
            foreach (string command in sqlCommands)
            {
                try
                {
                    SendProgressUpdate(count++);

                    statement = command.Trim();
                    if (!string.IsNullOrEmpty(statement))
                    {
                        if (useTransaction)
                        {
                            adapter.BeginTransaction();
                            adapter.ExecuteSql(statement);
                            adapter.CommitTransaction();
                        }
                        else
                        {
                            adapter.ExecuteSql(statement);
                        }
                    }

                    if (CancelPending())
                    {
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    if (useTransaction)
                    {
                        adapter.RollbackTransaction();
                    }

                    SendError(ex);
                    SystemTrace.Instance.Error(statement);
                    System.Diagnostics.Debug.WriteLine(ex.ToString());
                    System.Diagnostics.Debug.WriteLine(statement);
                    throw;
                }
            }

            Thread.Sleep(1000);
            SendProgressEnd();

            return(true);
        }
コード例 #2
0
        /// <summary>
        /// Drop all database instances that were created during this install.
        /// </summary>
        /// <param name="creationSQL">The SQL used to create the databases.</param>
        /// <param name="adapter">The SQL Text Adapter.</param>
        private void DropDatabaseInstances(IEnumerable <string> databaseNames, SqlTextAdapter adapter)
        {
            try
            {
                foreach (string databaseName in databaseNames)
                {
                    UpdateStatus(string.Format("Killing {0} database session.", databaseName));
                    //UpdateStatus(statement);
                    adapter.ExecuteNonQuery(Resources.UseMaster);
                    adapter.ExecuteSql(Resources.KillDatabaseProcessSql.FormatWith(databaseName));

                    UpdateStatus(string.Format("Dropping {0}.", databaseName));
                    adapter.ExecuteSql(Resources.UseMaster);
                    adapter.ExecuteSql(Resources.CloseConnectionSql.FormatWith(databaseName));
                    adapter.ExecuteSql(Resources.DropDatabaseSql.FormatWith(databaseName));
                }
            }
            catch (Exception ex)
            {
                UpdateStatus(ex.Message);
                Thread.Sleep(5000);
                SendError(ex);
            }
        }