Esempio n. 1
0
        private void nextButton_Click(object sender, System.EventArgs args)
        {
            if (steps.Current == steps.LastStep)
            {
                // Wizard completed successfully.

                closePromptedAlready = true;
                result = DBInstallResult.Installed;

                installer.server   = (string)setupState["server"];
                installer.database = (string)setupState["database"];
                installer.account  = (string)setupState["account"];
                installer.password = (string)setupState["password"];

                Close();
                return;
            }

            steps.StepNext();
        }
Esempio n. 2
0
        private bool PromptClose()
        {
            DialogResult dr;

            if (closePromptedAlready)
            {
                return(true);
            }

            dr = MessageBox.Show("Are you sure you want to cancel database setup?", installer.setupTitle,
                                 MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);

            if (dr == DialogResult.Yes)
            {
                closePromptedAlready = true;
                result = DBInstallResult.Cancelled;
            }

            return(closePromptedAlready);
        }
Esempio n. 3
0
        /// <summary>
        /// Performs a touch-free (no user interface) deployment of the database package.
        /// </summary>
        /// <returns>Information about the disposition of the installation.</returns>
        public DBInstallResult Install(DBInstallParams dbParams)
        {
            ArgCollection   args;
            DBInstallResult result = DBInstallResult.Unknown;;

            this.dbParams = dbParams;
            server        = dbParams.Server;
            database      = dbParams.Database;

            if (String.Compare(database, "MASTER", true) == 0)
            {
                throw new ArgumentException("Cannot deploy to the [MASTER] database.");
            }

            args     = ArgCollection.Parse(dbParams.AppSecurity);
            account  = args["uid"];
            password = args["pwd"];

            result = CheckDatabase();
            CheckAppAccount();

            switch (result)
            {
            case DBInstallResult.Installed:

                Install();
                break;

            case DBInstallResult.Upgraded:

                result = Upgrade();
                break;
            }

            return(result);
        }
Esempio n. 4
0
 /// <summary>
 /// Runs the installation wizard.
 /// </summary>
 /// <param name="installer">The package installer.</param>
 /// <returns>A DBInstallResult indicating what happened.</returns>
 public static DBInstallResult Install(DBPackageInstaller installer)
 {
     result = DBInstallResult.Unknown;
     Application.Run(new InstallWizard(installer));
     return(result);
 }
Esempio n. 5
0
        /// <summary>
        /// Used during touch-free deployment to verify that the database doesn't exist
        /// or is empty (in which case an installation needs to be performed) or if the
        /// database does exist and belongs to the same product (so an upgrade should
        /// be attempted).
        /// </summary>
        /// <returns>Indicates whether an install or upgrade should be performed.</returns>
        private DBInstallResult CheckDatabase()
        {
            // Take a look at the database and ensure that it is either empty
            // or is already associated with this product ID and database type.

            DBInstallResult result = DBInstallResult.Unknown;
            SqlContext      ctx;
            SqlCommand      cmd;
            DataTable       dt;
            string          cs;
            string          dbName;
            string          query;
            bool            exists;

            cs  = string.Format("server={0};database={1};{2}", server, database, dbParams.AdminSecurity);
            ctx = new SqlContext(cs);

            try
            {
                ctx.Open();

                // Create the database if the doesn't already exist.

                cmd    = ctx.CreateSPCall("sp_databases");
                dt     = ctx.ExecuteTable(cmd);
                exists = false;

                foreach (DataRow row in dt.Rows)
                {
                    dbName = SqlHelper.AsString(row["DATABASE_NAME"]);
                    if (String.Compare(dbName, database, true) == 0)
                    {
                        exists = true;
                        break;
                    }
                }

                if (!exists)
                {
                    if (dbParams.DBPath != null && dbParams.LogPath != null)
                    {
                        Helper.CreateFolderTree(dbParams.DBPath);
                        Helper.CreateFolderTree(dbParams.LogPath);
                        query = string.Format("create database [{0}] on (name='{0}_data', filename='{1}') log on (name='{0}_log', filename='{2}')", database, dbParams.DBPath, dbParams.LogPath);
                    }
                    else if (dbParams.DBPath != null)
                    {
                        Helper.CreateFolderTree(dbParams.DBPath);
                        query = string.Format("create database [{0}] on (name='{0}_data', filename='{1}')", database, dbParams.DBPath);
                    }
                    else
                    {
                        query = string.Format("create database [{0}]", database);
                    }

                    cmd = ctx.CreateCommand(query);
                    ctx.Execute(cmd);

                    return(DBInstallResult.Installed);
                }

                // I'm going to determine whether the database is empty or
                // not by looking at the sysobjects table.  We'll consider
                // it to be not empty if any these conditions are true:
                //
                //      1. Any user tables are present whose names
                //         don't begin with "dt".
                //
                //      2. Any stored procedures or functions are present
                //         whose names don't begin with "dt".


                cmd = ctx.CreateCommand("select 1 from sysobjects where (xtype='U' or xtype='P' or xtype='FN') and name not like 'dt%'");
                dt  = ctx.ExecuteTable(cmd);

                if (dt.Rows.Count == 0)
                {
                    // The database appears to be empty.

                    result = DBInstallResult.Installed;
                }
                else
                {
                    // The database appears to be not empty.  Try calling the
                    // GetProductInfo procedure.  If this fails then assume that
                    // the database belongs to some other application.  If it
                    // succeeds then check the productID and database type against
                    // the setup settings.

                    try
                    {
                        cmd = ctx.CreateSPCall("GetProductInfo");
                        dt  = ctx.ExecuteTable(cmd);

                        // Compare the database's product ID and database type to
                        // the setup settings.

                        if (SqlHelper.AsString(dt.Rows[0]["ProductID"]) != productID ||
                            SqlHelper.AsString(dt.Rows[0]["DatabaseType"]) != databaseType)
                        {
                            throw new InvalidOperationException(string.Format("Package cannot be deployed. Database [{0}] is configured for use by [{1}:{2}].",
                                                                              database, SqlHelper.AsString(dt.Rows[0]["ProductName"]), SqlHelper.AsString(dt.Rows[0]["DatabaseType"])));
                        }

                        // The database looks like can accept the installation.

                        result     = DBInstallResult.Upgraded;
                        curVersion = new Version(SqlHelper.AsString(dt.Rows[0]["SchemaVersion"]));
                    }
                    catch
                    {
                        throw new InvalidOperationException(string.Format("Database [{0}] is not empty and appears to in use by another application.\r\n\r\nPlease select a different database.", database));
                    }
                }
            }
            finally
            {
                ctx.Close();
            }

            Assertion.Test(result != DBInstallResult.Unknown);

            return(result);
        }