public ArrayList GetBackupSetPhysicalSources(int backupsetId)
        {
            SqlExecutionModes executionMode = this.sqlConnection.SqlExecutionModes;

            this.sqlConnection.SqlExecutionModes = SqlExecutionModes.ExecuteSql;

            ArrayList sources   = new ArrayList();
            DataSet   backupSet = GetBackupSetById(backupsetId);

            if (backupSet.Tables[0].Rows.Count == 1)
            {
                string mediaSetID = Convert.ToString(backupSet.Tables[0].Rows[0]["MediaSetId"], System.Globalization.CultureInfo.InvariantCulture);

                Enumerator en          = new Enumerator();
                Request    req         = new Request();
                DataSet    mediafamily = new DataSet();
                mediafamily.Locale = System.Globalization.CultureInfo.InvariantCulture;

                req.Urn     = "Server/BackupMediaSet[@ID='" + Urn.EscapeString(mediaSetID) + "']/MediaFamily";
                mediafamily = en.Process(this.sqlConnection, req);

                if (mediafamily.Tables[0].Rows.Count > 0)
                {
                    for (int j = 0; j < mediafamily.Tables[0].Rows.Count; j++)
                    {
                        RestoreItemSource itemSource = new RestoreItemSource();
                        itemSource.RestoreItemLocation = Convert.ToString(mediafamily.Tables[0].Rows[j]["PhysicalDeviceName"], System.Globalization.CultureInfo.InvariantCulture);
                        BackupDeviceType backupDeviceType = (BackupDeviceType)Enum.Parse(typeof(BackupDeviceType), mediafamily.Tables[0].Rows[j]["BackupDeviceType"].ToString());

                        if (BackupDeviceType.Disk == backupDeviceType)
                        {
                            itemSource.RestoreItemDeviceType = DeviceType.File;
                        }
                        else if (BackupDeviceType.Url == backupDeviceType)
                        {
                            itemSource.RestoreItemDeviceType = DeviceType.Url;
                        }
                        else
                        {
                            itemSource.RestoreItemDeviceType = DeviceType.Tape;
                        }
                        sources.Add(itemSource);
                    }
                }
            }

            this.sqlConnection.SqlExecutionModes = executionMode;
            return(sources);
        }
        public DataSet GetBackupSetById(int backupsetId)
        {
            SqlExecutionModes executionMode = this.sqlConnection.SqlExecutionModes;

            this.sqlConnection.SqlExecutionModes = SqlExecutionModes.ExecuteSql;
            Enumerator en        = new Enumerator();
            Request    req       = new Request();
            DataSet    backupset = new DataSet();

            backupset.Locale = System.Globalization.CultureInfo.InvariantCulture;

            req.Urn   = "Server/BackupSet[@ID='" + Urn.EscapeString(Convert.ToString(backupsetId, System.Globalization.CultureInfo.InvariantCulture)) + "']";
            backupset = en.Process(this.sqlConnection, req);

            this.sqlConnection.SqlExecutionModes = executionMode;
            return(backupset);
        }
예제 #3
0
        private int GetDeviceType(string deviceName)
        {
            Enumerator enumerator = new Enumerator();
            Request    request    = new Request();
            DataSet    dataset    = new DataSet();

            dataset.Locale = System.Globalization.CultureInfo.InvariantCulture;
            int result = -1;
            SqlExecutionModes executionMode = this.serverConnection.SqlExecutionModes;

            this.serverConnection.SqlExecutionModes = SqlExecutionModes.ExecuteSql;
            try
            {
                request.Urn       = "Server/BackupDevice[@Name='" + Urn.EscapeString(deviceName) + "']";
                request.Fields    = new string[1];
                request.Fields[0] = "BackupDeviceType";
                dataset           = enumerator.Process(this.serverConnection, request);
                if (dataset.Tables[0].Rows.Count > 0)
                {
                    result = Convert.ToInt16(dataset.Tables[0].Rows[0]["BackupDeviceType"],
                                             System.Globalization.CultureInfo.InvariantCulture);
                }
                else
                {
                    result = constDeviceTypeMediaSet;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                this.serverConnection.SqlExecutionModes = executionMode;
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// called when we need to script a Sql server dlg.
        /// </summary>
        /// <param name="executionInfo"></param>
        /// <param name="executionResult"></param>
        private void ExecuteForSql(PreProcessExecutionInfo executionInfo, out ExecutionMode executionResult)
        {
            Microsoft.SqlServer.Management.Smo.Server oldServer = null;
            if (NeedToSwitchServer)
            {
                // We use a new instance of the SMO Server object every time we script
                // so that any changes that are made to the SMO server while scripting are
                // not kept when the script operation is completed.
                oldServer = DataContainer.Server;

                //BUGBUG - see if we can use copy ctor instead
                DataContainer.Server = new Microsoft.SqlServer.Management.Smo.Server(DataContainer.ServerConnection);
            }

            String szScript              = null;
            bool   isScripting           = IsScripting(executionInfo.RunType);
            var    executionModeOriginal = GetServerConnectionForScript().SqlExecutionModes;
            //For Azure the ExecutionManager is different depending on which ExecutionManager
            //used - one at the Server level and one at the Database level. So to ensure we
            //don't use the wrong execution mode we need to set the mode for both (for on-prem
            //this will essentially be a no-op)
            SqlExecutionModes subjectExecutionModeOriginal = executionModeOriginal;
            SqlSmoObject      sqlDialogSubject             = null;

            try
            {
                sqlDialogSubject = this.DataContainer.SqlDialogSubject;
            }
            catch (System.Exception)
            {
                //We may not have a valid dialog subject here (such as if the object hasn't been created yet)
                //so in that case we'll just ignore it as that's a normal scenario.
            }

            if (sqlDialogSubject != null)
            {
                subjectExecutionModeOriginal = sqlDialogSubject.ExecutionManager.ConnectionContext.SqlExecutionModes;
            }
            try
            {
                SqlExecutionModes newMode = isScripting
                    ? SqlExecutionModes.CaptureSql
                    : SqlExecutionModes.ExecuteSql;
                //now, do the execution itself
                GetServerConnectionForScript().SqlExecutionModes = newMode;
                if (sqlDialogSubject != null)
                {
                    sqlDialogSubject.ExecutionManager.ConnectionContext.SqlExecutionModes = newMode;
                }

                executionResult = DoPreProcessExecutionAndRunViews(executionInfo.RunType);

                if (isScripting)
                {
                    if (executionResult == ExecutionMode.Success)
                    {
                        szScript = BuildSqlScript();
                    }
                }
            }
            finally
            {
                GetServerConnectionForScript().SqlExecutionModes = executionModeOriginal;

                if (isScripting)
                {
                    GetServerConnectionForScript().CapturedSql.Clear();
                }

                if (sqlDialogSubject != null)
                {
                    sqlDialogSubject.ExecutionManager.ConnectionContext.SqlExecutionModes = subjectExecutionModeOriginal;
                    if (isScripting)
                    {
                        sqlDialogSubject.ExecutionManager.ConnectionContext.CapturedSql.Clear();
                    }
                }

                //see if we need to restore the server
                if (oldServer != null)
                {
                    DataContainer.Server = oldServer;
                }
            }

            if (isScripting)
            {
                executionInfo.Script = szScript;
            }
        }