/// <summary>
        /// Executes the script.
        /// </summary>
        /// <returns></returns>
        public ScriptResult ExecuteScript()
        {
            var errors  = new ScriptErrorCollection();
            var success = false;

            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.InfoMessage += cn_InfoMessage;
                connection.Open();

                foreach (Batch batch in SplitScript(Script))
                {
                    using (IDbCommand cmd = connection.CreateCommand())
                    {
                        cmd.CommandType = CommandType.Text;
                        cmd.CommandText = batch.Content;
                        cmd.Connection  = connection;

                        try
                        {
                            cmd.ExecuteNonQuery();
                        }
                        catch (SqlException ex)
                        {
                            foreach (SqlError error in ex.Errors)
                            {
                                errors.Add(new ScriptError(error.Number, error.State, error.Class,
                                                           error.Message, error.Procedure,
                                                           error.LineNumber + batch.StartLineNumber - 1));
                            }
                        }
                    }
                }

                if (connection.State != ConnectionState.Closed)
                {
                    connection.Close();
                }
            }

            if (errors.Count == 0)
            {
                success = true;
            }

            return(new ScriptResult(success, errors));
        }
 public ScriptResult(bool success, ScriptErrorCollection errors)
 {
     Success = success;
     Errors  = errors;
 }