protected virtual void SaveProperties()

in src/Microsoft.SqlTools.ServiceLayer/Admin/Database/DatabasePrototype.cs [2303:2434]


        protected virtual void SaveProperties(Database db)
        {
            if (!this.Exists || (db.DatabaseOptions.UserAccess != this.currentState.restrictAccess))
            {
                db.DatabaseOptions.UserAccess = this.currentState.restrictAccess;
            }

            if (!this.Exists || (db.DatabaseOptions.CloseCursorsOnCommitEnabled != this.CloseCursorOnCommit))
            {
                db.DatabaseOptions.CloseCursorsOnCommitEnabled = this.CloseCursorOnCommit;
            }

            if (db.IsSupportedProperty("LocalCursorsDefault"))
            {
                bool localCursorsDefault = (this.currentState.defaultCursor == DefaultCursor.Local);
                if (!this.Exists || (db.DatabaseOptions.LocalCursorsDefault != localCursorsDefault))
                {
                    db.DatabaseOptions.LocalCursorsDefault = localCursorsDefault;
                }
            }

            if (db.IsSupportedProperty("AutoClose"))
            {
                if (!this.Exists || (db.DatabaseOptions.AutoClose != this.AutoClose))
                {
                    db.DatabaseOptions.AutoClose = this.AutoClose;
                }
            }

            if (!this.Exists || (db.DatabaseOptions.AutoShrink != this.AutoShrink))
            {
                db.DatabaseOptions.AutoShrink = this.AutoShrink;
            }

            if (!this.Exists || (db.DatabaseOptions.AutoCreateStatistics != this.AutoCreateStatistics))
            {
                db.DatabaseOptions.AutoCreateStatistics = this.AutoCreateStatistics;
            }

            if (db.IsSupportedProperty("AutoCreateIncrementalStatisticsEnabled") &&
                (!this.Exists || db.DatabaseOptions.AutoCreateStatisticsIncremental != this.AutoCreateStatisticsIncremental))
            {
                db.DatabaseOptions.AutoCreateStatisticsIncremental = this.AutoCreateStatisticsIncremental;
            }

            if (!this.Exists || (db.DatabaseOptions.AutoUpdateStatistics != this.AutoUpdateStatistics))
            {
                db.DatabaseOptions.AutoUpdateStatistics = this.AutoUpdateStatistics;
            }

            if (!this.Exists || (db.DatabaseOptions.AnsiNullDefault != this.AnsiNullDefault))
            {
                db.DatabaseOptions.AnsiNullDefault = this.AnsiNullDefault;
            }

            if (!this.Exists || (db.DatabaseOptions.AnsiNullsEnabled != this.AnsiNulls))
            {
                db.DatabaseOptions.AnsiNullsEnabled = this.AnsiNulls;
            }

            if (!this.Exists || (db.DatabaseOptions.QuotedIdentifiersEnabled != this.QuotedIdentifier))
            {
                db.DatabaseOptions.QuotedIdentifiersEnabled = this.QuotedIdentifier;
            }

            if (!this.Exists || (db.DatabaseOptions.RecursiveTriggersEnabled != this.RecursiveTriggers))
            {
                db.DatabaseOptions.RecursiveTriggersEnabled = this.RecursiveTriggers;
            }

            if (db.IsSupportedProperty("RecoveryModel"))
            {
                if (!this.Exists || (db.DatabaseOptions.RecoveryModel != this.RecoveryModel))
                {
                    db.DatabaseOptions.RecoveryModel = this.RecoveryModel;
                }
            }

            // user has to be a sysadmin to set full text indexing settings or compatibility level
            // Azure SQL DB doesn't have a fixed server role for sysadmin
            if (db.Parent.ConnectionContext.IsInFixedServerRole(FixedServerRoles.SysAdmin) || db.DatabaseEngineType == DatabaseEngineType.SqlAzureDatabase)
            {
                // Full-text indexing will always be enabled in Katmai
                if (this.serverVersion.Major <= 9 && db.Parent.Information.IsFullTextInstalled &&
                    (!this.Exists || (db.IsFullTextEnabled != this.FullTextIndexing)))
                {
                    db.IsFullTextEnabled = this.FullTextIndexing;
                }

                if (!this.Exists || (db.CompatibilityLevel != this.DatabaseCompatibilityLevel))
                {
                    db.CompatibilityLevel = this.DatabaseCompatibilityLevel;
                }
            }

            // $FUTURE: 6/25/2004-stevetw Consider moving mirroring property sets
            // to a Yukon-specific subclass
            if (db.IsSupportedProperty("IsMirroringEnabled"))
            {
                if (this.Exists && db.IsMirroringEnabled && (db.MirroringSafetyLevel != MirrorSafetyLevel))
                {
                    db.MirroringSafetyLevel = this.MirrorSafetyLevel;
                }

                if (this.Exists && db.IsMirroringEnabled && (string.Compare(db.MirroringWitness, this.MirrorWitness, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    if (this.MirrorWitness.Length == 0) // we want to remove it
                    {
                        db.ChangeMirroringState(MirroringOption.RemoveWitness);
                    }
                    else
                    {
                        db.MirroringWitness = this.MirrorWitness;
                    }
                }
            }

            if (db.IsSupportedProperty("FilestreamDirectoryName"))
            {
                if ((!this.Exists && !string.IsNullOrEmpty(this.FilestreamDirectoryName)) ||
                  (this.Exists && string.Compare(db.FilestreamDirectoryName, this.FilestreamDirectoryName, StringComparison.OrdinalIgnoreCase) != 0))
                {
                    db.FilestreamDirectoryName = this.FilestreamDirectoryName;
                }

                if ((!this.Exists && this.FilestreamNonTransactedAccess != FilestreamNonTransactedAccessType.Off) ||
                    (this.Exists && db.FilestreamNonTransactedAccess != this.FilestreamNonTransactedAccess))
                {
                    db.FilestreamNonTransactedAccess = this.FilestreamNonTransactedAccess;
                }
            }
        }