/// <summary>
 /// create credential - create mode
 /// </summary>
 private void SendToServerCreateCredential()
 {
     Microsoft.SqlServer.Management.Smo.Credential smoCredential = new Microsoft.SqlServer.Management.Smo.Credential(
         this.Context.Server,
         this.CredentialName);
     if (this.isEncryptionByProvider)
     {
         smoCredential.MappedClassType = MappedClassType.CryptographicProvider;
         smoCredential.ProviderName    = this.providerName;
     }
     smoCredential.Create(this.CredentialIdentity, this.SecurePassword.ToString());
     GC.Collect();             // this.SecurePassword.ToString() just created an immutable string that lives in memory
 }
        /// <summary>
        /// alter credential - properties mode
        /// </summary>
        private void SendToServerAlterCredential()
        {
            Microsoft.SqlServer.Management.Smo.Credential smoCredential = this.Context.Server.Credentials[this.CredentialName];

            if (smoCredential != null)
            {
                if (this.PasswordWasChanged == false)
                {
                    if (smoCredential.Identity != this.CredentialIdentity)
                    {
                        smoCredential.Alter(this.CredentialIdentity);
                    }
                }
                else
                {
                    smoCredential.Alter(this.CredentialIdentity, this.SecurePassword.ToString());
                    GC.Collect();                     // this.SecurePassword.ToString() just created an immutable string that lives in memory
                }
            }
            else
            {
                throw new Exception("SRError.CredentialNoLongerExists");
            }
        }