示例#1
0
        /// <summary>
        /// Performs an install of a database
        /// </summary>
        public void Install(InstallSetup setup)
        {
            //The connection string must reference an existing database
            if (!DatabaseServer.TestConnectionString(setup.ConnectionString))
            {
                throw new Exception("The connection string does not reference a valid database.");
            }

            try
            {
                UpgradeInstaller.UpgradeDatabase(setup);
            }
            catch (InvalidSQLException ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine("BEGIN ERROR SQL");
                sb.AppendLine(ex.SQL);
                sb.AppendLine("END ERROR SQL");
                sb.AppendLine();
                Log.Verbose(sb.ToString());
                UpgradeInstaller.LogError(ex, sb.ToString());
                throw;
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#2
0
        /// <summary>
        /// Performs an install of a database
        /// </summary>
        public void Install(InstallSetup setup)
        {
            if (setup.InstallStatus == InstallStatusConstants.Create)
            {
                //Connection cannot reference an existing database
                if (DatabaseServer.TestConnectionString(setup.ConnectionString))
                {
                    throw new Exception("The connection string references an existing database.");
                }

                //The new database name must be specified
                if (string.IsNullOrEmpty(setup.NewDatabaseName))
                {
                    throw new Exception("A new database name was not specified.");
                }

                //The connection string and the new database name must be the same
                var builder = new Npgsql.NpgsqlConnectionStringBuilder(setup.ConnectionString);
                if (builder.Database.ToLower() != setup.NewDatabaseName.ToLower())
                {
                    throw new Exception("A new database name does not match the specified connection string.");
                }

                DatabaseServer.CreateDatabase(setup);
            }
            else if (setup.InstallStatus == InstallStatusConstants.Upgrade)
            {
                //The connection string must reference an existing database
                if (!DatabaseServer.TestConnectionString(setup.ConnectionString))
                {
                    throw new Exception("The connection string does not reference a valid database.");
                }
            }

            try
            {
                UpgradeInstaller.UpgradeDatabase(setup);
            }
            catch (InvalidSQLException ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine();
                sb.AppendLine("BEGIN ERROR SQL");
                sb.AppendLine(ex.SQL);
                sb.AppendLine("END ERROR SQL");
                sb.AppendLine();
                System.Diagnostics.Trace.WriteLine(sb.ToString());
                UpgradeInstaller.LogError(ex, sb.ToString());
                throw;
            }
            catch (Exception ex)
            {
                throw;
            }
        }