public void Attach()
        {
            if (this.RunningState == RunningState.Attached)
            {
                throw new DeployException(ExceptionMessages.CannotAttachDatabase);
            }

            // collect filenames for attach
            System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection();

            this.LoadAllChildren();
            foreach (DatabaseInstanceFileGroup fg in this.FileGroups.Values)
            {
                fg.LoadAllChildren();
                foreach (DatabaseInstanceFile f in fg.Files.Values)
                {
                    files.Add(f.GetFullLocalFilename());
                }
            }

            smo::Server dserver = this.ServerInstance.GetSmoServer();

            dserver.AttachDatabase(this.DatabaseName, files);

            this.DeploymentState = DeploymentState.Deployed;
            this.RunningState = RunningState.Attached;
            this.Save();

            this.Context.LogEvent(new Event("Jhu.Graywulf.Registry.DatabaseInstance.Attach", this.Guid));
        }
        /// <summary>
        /// Allocates database files and creates file groups without copying
        /// database objects
        /// </summary>
        /// <param name="databaseInstance">The database instance object.</param>
        public override void Deploy()
        {
            // Make sure it's new or undeployed
            if (this.DeploymentState != DeploymentState.New &&
                this.DeploymentState != DeploymentState.Undeployed)
            {
                throw new DeployException(ExceptionMessages.CannotDeployDatabase);
            }

            // Change deployment state to deploying
            this.DeploymentState = DeploymentState.Deploying;
            this.Save();

            // Get SMO object to the target database
            smo::Server sto = this.ServerInstance.GetSmoServer();
            smo::Database dto = new smo::Database(sto, this.DatabaseName);
            
            // Important non-default settings
            dto.RecoveryModel = smo.RecoveryModel.Simple;
            dto.Collation = "SQL_Latin1_General_CP1_CI_AS";

            // --- Delete old LogFiles, FileGroups and create new ones ---
            DropLogFiles(dto);
            DropFileGroups(dto);
            this.CreateFileGroups(dto);

            // Create the empty database with filegroups and files
            dto.Create();
            this.Context.LogEvent(new Event("Jhu.Graywulf.Registry.DatabaseInstance.Deploy[Create database]", this.Guid));

            // Change deployment state to deployed
            this.DeploymentState = DeploymentState.Deployed;
            this.RunningState = RunningState.Attached;
            this.Save();

            this.Context.LogEvent(new Event("Jhu.Graywulf.Registry.DatabaseInstance.Deploy[Done]", this.Guid));
        }
Beispiel #3
0
        /// <summary>
        /// Returns an SMO database object referencing the database instance.
        /// </summary>
        /// <param name="databaseInstance">The database instance object.</param>
        /// <returns>An SMO database object connected to the database instance.</returns>
        public smo::Database GetSmoDatabase()
        {
            smo::Server s = this.ServerInstance.GetSmoServer();

            return(s.Databases[databaseName]);
        }