Click here to Skip to main content
15,889,651 members
Articles / Programming Languages / SQL
Tip/Trick

Set global profile for mailing in Microsoft SQL Server 2008

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Nov 2010CPOL 35.2K   4   1
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)


Written By
Database Developer Freelancer
Ukraine Ukraine
MS SQL Server Database Developer with 7+ years experience

Technologies/languages: Business Intelligence, SQL, MDX, VBA, SQL Server, Analysis Services (SSAS), Reporting services (SSRS), Integration Services (SSIS), DataWarehouse.
Also: economic background.

Feel free to contact me for rates and details.

Comments and Discussions

 
GeneralGreat Article Pin
rohitkharbanda18-Mar-12 19:44
rohitkharbanda18-Mar-12 19:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.