Exemple #1
0
        private void CheckAndUpgradeSchema()
        {
            OMLEngine.DatabaseManagement.DatabaseManagement dbm = new OMLEngine.DatabaseManagement.DatabaseManagement();

            OMLEngine.DatabaseManagement.DatabaseInformation.SQLState state = dbm.CheckDatabase();

            if (state == OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.OMLDBNotFound)
            {
                MessageBox.Show("Detected SQL Server but cannot find the database. Click OK to create the database.", "Databse problem", MessageBoxButtons.OK);
                // OML Instance but OML database does not exist
                dbm.ConfigureSQL(ScriptsPath);
                dbm.UpgradeSchemaVersion(ScriptsPath);

                // Retest the connection
                state = dbm.CheckDatabase();
            }

            if (state == OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.OMLDBVersionUpgradeRequired)
            {
                MessageBox.Show("Detected the OML Database but it requires updating. Click OK to update the database.", "Databse problem", MessageBoxButtons.OK);
                dbm.UpgradeSchemaVersion(ScriptsPath);

                // Retest the connection
                state = dbm.CheckDatabase();
            }

            if (state == OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.OK)
            {
                MessageBox.Show("The database appears all fine.", "Database status", MessageBoxButtons.OK);
                return;
            }
        }
Exemple #2
0
        private bool TestDBConnection(AddInHost host)
        {
            try
            {
                //return OMLEngine.Settings.OMLSettings.IsConnected;
                OMLEngine.DatabaseManagement.DatabaseManagement           dbm   = new OMLEngine.DatabaseManagement.DatabaseManagement();
                OMLEngine.DatabaseManagement.DatabaseInformation.SQLState state = dbm.CheckDatabase();
                switch (state)
                {
                case OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.OK:
                    return(true);

                case OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.OMLDBVersionCodeOlderThanSchema:
                    throw (new Exception("The OML client is an older version than the database. Please upgrade the client components!"));

                //is this right?
                case OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.OMLDBVersionNotFound:
                    return(true);

                case OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.LoginFailure:
                    return(false);

                case OMLEngine.DatabaseManagement.DatabaseInformation.SQLState.OMLDBVersionUpgradeRequired:
                {
                    //TODO: do upgrade bits here...
                    return(true);
                }

                default:
                    throw (new Exception(OMLEngine.DatabaseManagement.DatabaseInformation.LastSQLError));
                }
            }
            catch (Exception ex)
            {
                host.MediaCenterEnvironment.Dialog(
                    ex.Message,
                    "CONNECTION FAILED", Microsoft.MediaCenter.DialogButtons.Ok, 5, false);
                return(false);

                //this._session.Close();
            }
            return(true);
        }