If you’re getting a “profile name is not valid” error when updating a Database Mail profile in SQL Server, it could be that you’ve forgotten to provide the profile ID.
When you update a Database Mail profile with the sysmail_update_profile_sp
stored procedure, you need to include the profile ID if you want to update the profile name.
Example
Imagine we run the following code to return all Database Mail profiles:
EXEC msdb.dbo.sysmail_help_profile_sp;
Result:
+--------------+------------------+---------------------------+ | profile_id | name | description | |--------------+------------------+---------------------------| | 1 | DB Admin Profile | Profile for admin emails. | +--------------+------------------+---------------------------+
And so we decide to update the name of this profile from “DB Admin Profile” to “New DB Admin Profile”.
Here’s an example of how not to do it (i.e. how to produce the error).
EXECUTE msdb.dbo.sysmail_update_profile_sp
@profile_name = 'New DB Admin Profile',
@description = 'Profile for admin emails.';
In this case, I provide the new name and the existing description. But that’s not going to cut it.
Running that will produce the following error:
Msg 14607, Level 16, State 1, Procedure msdb.dbo.sysmail_verify_profile_sp, Line 42 profile name is not valid
To do it correctly, you need to provide the profile ID:
EXECUTE msdb.dbo.sysmail_update_profile_sp
@profile_id = 1,
@profile_name = 'New DB Admin Profile',
@description = 'Profile for admin emails.';
Result:
Commands completed successfully.
Now when I check my list of profiles, I see the updated profile name.
EXEC msdb.dbo.sysmail_help_profile_sp;
Result:
+--------------+----------------------+---------------------------+ | profile_id | name | description | |--------------+----------------------+---------------------------| | 1 | New DB Admin Profile | Profile for admin emails. | +--------------+----------------------+---------------------------+
Note that you don’t need to provide the profile ID if you’re only updating the description (as long as you provide the correct profile name).