Exemple #1
0
        private void bgwSetupConnection_DoWork(object sender, DoWorkEventArgs e)
        {
            clsDatabaseConfig objdb        = (clsDatabaseConfig)e.Argument;
            string            errorMessage = "";

            if (objdb.IsNewDatabase)
            {
                bgwSetupConnection.ReportProgress(10, "(1/6) Creating the database file...");
                errorMessage = objdb.CreateNewDatabase();
                if (errorMessage != ErrorStates.Success.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Creating the database failed.");
                    e.Result = "Following error occured while creating the database:" + Environment.NewLine + errorMessage;
                    return;
                }

                bgwSetupConnection.ReportProgress(30, "(2/6) Verifying if database was attached...");
                errorMessage = objdb.IsNewDatabaseAttached();
                if (errorMessage == ErrorStates.Failure.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Database was not attached to the server.");
                    e.Result = "Database was not attached to the server." + Environment.NewLine + "Try attaching it manually and rerun the configuration process";
                    return;
                }
                else if (errorMessage != ErrorStates.Success.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Verifying the attached database failed.");
                    e.Result = "Following error occured while verifying the attached database:" + Environment.NewLine + errorMessage;
                    return;
                }

                bgwSetupConnection.ReportProgress(50, "(3/6) Installing schema onto the blank database...");
                errorMessage = objdb.InstallScriptFile(Application.StartupPath + "\\Scripts\\InstallDatabaseSchema.sql");
                if (errorMessage != ErrorStates.Success.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Installing schema to the database failed.");
                    e.Result = "Following error occured while installing schema to the database:" + Environment.NewLine + errorMessage;
                    return;
                }

                bgwSetupConnection.ReportProgress(70, "(4/6) Verifying the integrifty of database schema...");
                errorMessage = objdb.VerifySchema(Application.StartupPath + "\\Scripts\\InstallDatabaseSchema.sql");
                if (errorMessage != ErrorStates.Success.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Verifying integrity of the database schema failed.");
                    e.Result = "Following error occured while verifying integrity of the database schema:" + Environment.NewLine + errorMessage;
                    return;
                }

                bgwSetupConnection.ReportProgress(90, "(5/6) Fetching connection settings...");
                System.Threading.Thread.Sleep(500);
                e.Result = "|Success|" + objdb.GetConnectionString();

                bgwSetupConnection.ReportProgress(100, "(6/6) Database connection complete. Opening application...");
                System.Threading.Thread.Sleep(1000);
            }
            else
            {
                bgwSetupConnection.ReportProgress(10, "(1/5) Attaching the database file...");
                errorMessage = objdb.AttachExistingDatabase();
                if (errorMessage != ErrorStates.Success.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Attaching the database failed.");
                    e.Result = "Following error occured while attaching the database:" + Environment.NewLine + errorMessage;
                    return;
                }

                bgwSetupConnection.ReportProgress(30, "(2/5) Verifying if database was attached...");
                errorMessage = objdb.IsExistingDatabaseAttached();
                if (errorMessage == ErrorStates.Failure.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Database was not attached to the server.");
                    e.Result = "Database was not attached to the server." + Environment.NewLine + "Try attaching it manually and rerun the configuration process";
                    return;
                }
                else if (errorMessage != ErrorStates.Success.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Verifying the attached database failed.");
                    e.Result = "Following error occured while verifying the attached database:" + Environment.NewLine + errorMessage;
                    return;
                }

                bgwSetupConnection.ReportProgress(50, "(3/5) Verifying the integrifty of database schema...");
                errorMessage = objdb.VerifySchema(Application.StartupPath + "\\Scripts\\InstallDatabaseSchema.sql");
                if (errorMessage != ErrorStates.Success.ToString())
                {
                    bgwSetupConnection.ReportProgress(100, "Verifying integrity of the database schema failed.");
                    e.Result = "Following error occured while verifying integrity of the database schema:" + Environment.NewLine + errorMessage;
                    return;
                }

                bgwSetupConnection.ReportProgress(85, "(4/5) Fetching connection settings...");
                System.Threading.Thread.Sleep(500);
                e.Result = "|Success|" + objdb.GetConnectionString();

                bgwSetupConnection.ReportProgress(100, "(5/5) Database connection complete. Opening application...");
                System.Threading.Thread.Sleep(1000);
            }
        }
Exemple #2
0
        private void bgwSetServer_DoWork(object sender, DoWorkEventArgs e)
        {
            clsDatabaseConfig objdb = (clsDatabaseConfig)e.Argument;

            e.Result = objdb.IsServerNameValid();
        }