Esempio n. 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);
        }
Esempio n. 2
0
        private bool UpdateVersion(string databaseHost, Version version)
        {
            // Update the STB/STF version on the defined database host.
            string updateVersionSql = new EmbeddedResource("HP.SolutionTest.DatabaseCreation").Read("ins_SchemaVersion.sql");

            using (var adapter = new SqlTextAdapter(databaseHost, "Master"))
            {
                adapter.BeginTransaction();
                if (!ExecuteSql(updateVersionSql.FormatWith(version.ToString()), adapter, false))
                {
                    adapter.RollbackTransaction();
                    return(false);
                }
                adapter.CommitTransaction();
                _ticket.CurrentVersion = version;
            }

            return(true);
        }