public bool Drop() { if (this.DataContainer.Server.JobServer.ProxyAccounts.Contains(this.proxyAccountName)) { // Try refresh and check again this.DataContainer.Server.JobServer.ProxyAccounts.Refresh(); if (this.DataContainer.Server.JobServer.ProxyAccounts.Contains(this.proxyAccountName)) { ProxyAccount proxyAccount = AgentProxyAccountActions.GetProxyAccount(this.proxyAccountName, this.DataContainer.Server.JobServer); proxyAccount.DropIfExists(); } } return(false); }
/// <summary> /// It creates a new ProxyAccount or gets an existing /// one from JobServer and updates all properties. /// </summary> private bool CreateOrUpdateProxyAccount(AgentProxyInfo proxyInfo) { ProxyAccount proxyAccount = null; if (this.configAction == ConfigAction.Create) { proxyAccount = new ProxyAccount(this.DataContainer.Server.JobServer, proxyInfo.AccountName, proxyInfo.CredentialName, proxyInfo.IsEnabled, proxyInfo.Description); UpdateProxyAccount(proxyAccount); proxyAccount.Create(); } else if (this.DataContainer.Server.JobServer.ProxyAccounts.Contains(this.proxyAccountName)) { // Try refresh and check again this.DataContainer.Server.JobServer.ProxyAccounts.Refresh(); if (this.DataContainer.Server.JobServer.ProxyAccounts.Contains(this.proxyAccountName)) { proxyAccount = AgentProxyAccountActions.GetProxyAccount(this.proxyAccountName, this.DataContainer.Server.JobServer); // Set the other properties proxyAccount.CredentialName = proxyInfo.CredentialName; proxyAccount.Description = proxyInfo.Description; UpdateProxyAccount(proxyAccount); proxyAccount.Alter(); // Rename the proxy if needed // This has to be done after Alter, in order to // work correcly when scripting this action. if (this.proxyAccountName != proxyInfo.AccountName) { proxyAccount.Rename(proxyInfo.AccountName); } } } else { return(false); } return(true); #if false // @TODO - reenable subsystem code below // Update the subsystems foreach (AgentSubSystem subsystem in this.addSubSystems) { proxyAccount.AddSubSystem(subsystem); } foreach (AgentSubSystem subsystem in this.removeSubSystems) { proxyAccount.RemoveSubSystem(subsystem); // Update jobsteps that use this proxy accunt // when some subsystems are removed from it string reassignToProxyName = this.reassignToProxyNames[(int)subsystem]; if (reassignToProxyName != null) { // if version is sql 11 and above call SMO API to reassign proxy account if (Utils.IsSql11OrLater(this.DataContainer.Server.ServerVersion)) { proxyAccount.Reassign(reassignToProxyName); } else { // legacy code // Get a list of all job step objects that use this proxy and this subsystem Request req = new Request(); req.Urn = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Server/JobServer/Job/Step[@ProxyName=\'{0}\' and @SubSystem={1}]", Urn.EscapeString(proxyAccount.Name), (int)subsystem); req.Fields = new string[] { "Name" }; req.ParentPropertiesRequests = new PropertiesRequest[1] { new PropertiesRequest() }; req.ParentPropertiesRequests[0].Fields = new string[] { "Name" }; Enumerator en = new Enumerator(); DataTable table = en.Process(this.DataContainer.ServerConnection, req); foreach (DataRow row in table.Rows) { // Get the actual job step object using urn string urnString = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Server/JobServer/Job[@Name=\"{0}\"/Step[@Name=\"{1}\"", row["Job_Name"], row["Name"]); Urn urn = new Urn(urnString); JobStep jobStep = (JobStep)this.DataContainer.Server.GetSmoObject(urn); jobStep.ProxyName = reassignToProxyName; jobStep.Alter(); } } } } #endif }