Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / SQL

Set global profile for mailing in Microsoft SQL Server 2008

5.00/5 (1 vote)
13 Nov 2010CPOL 35.5K  
Allows to set default mailing global profile with aid of T-SQL

You can get an error message like the following:


Msg 14636, Level 16, State 1, Procedure sp_send_dbmail, Line 112
No global profile is configured. Specify a profile name in the @profile_name parameter.



Yes. You forgot to set up default profile in Database Mail Configuration Wizard just like me. :) There is no simple way to correct this.


I checked sysmail_ stored procedures family on subject who is able to handle this situation. The most relevant one is sysmail_update_principalprofile_sp, but I dropped the idea to use it after the first failed attempt to do. I checked sysmail_ tables set instead. And I quickly found [msdb].[dbo].[sysmail_principalprofile] with is_default field in it.


This is T-SQL to set default mailing profile:



SQL
update [msdb].[dbo].[sysmail_principalprofile]
set is_default = 1
where profile_id =
      (select max(profile_id)
      from [msdb].[dbo].[sysmail_profile]
      where [name] = 'def_profile'
      )


From now annoying offer to specify a profile name in the @profile_name parameter disappeared.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)