title: Alter failed for ProxyAccount 'yyy' (Microsoft.SqlServer.Smo)
body: <p>I am running into an issue when trying to script the creation of a credential and related proxy in Microsoft SQL Server Management Studio.</p>
  
  <p>My script is the following:</p>
  
  <pre><code>CREATE CREDENTIAL xxx WITH IDENTITY = 'domain\xxx', SECRET = '*******';
  
  EXEC msdb.dbo.sp_add_proxy @proxy_name  = 'yyy' 
  ,@enabled = 1 
  ,@description = 'description here'
  ,@credential_name = 'xxx'
  
  EXEC msdb.dbo.sp_grant_proxy_to_subsystem @proxy_name = 'yyy'
  ,@subsystem_id = 9;
  </code></pre>
  
  <p>This creates both the credential and the proxy. </p>
  
  <p>HOWEVER, it fails to add the credential correctly to the proxy. When trying to manually (with the UI) add the credential I receive the following error:</p>
  
  <blockquote>
    <p>Alter failed for ProxyAccount 'yyy' (Microsoft.SqlServer.Smo)
    Additional Information:
        Object reference not set to an instance of an object. (Microsoft.SqlServer.Smo)</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/WokJi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WokJi.png" alt="Attempt to add credential"></a></p>
  
  <p><a href="https://i.stack.imgur.com/aLHvf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/aLHvf.png" alt="Error message"></a></p>
  
  <p>I have tried dropping the credential and re-adding it with no results. I've tried to drop and re-add the proxy but I receive the following error:</p>
  
  <blockquote>
    <p>The credential name for the proxy is not defined. (SqlManagerUI)</p>
  </blockquote>
  
  <p>Which goes back to not being able to assign a credential to that proxy.</p>