2012-09-17 78 views
1

我正在嘗試發送Sproc結果的電子郵件。我曾試着這樣做:將Sproc結果發送到SQL Server中的電子郵件

EXEC msdb.dbo.sp_send_dbmail 
    @recipients = '[email protected]', 
    @query = 'EXEC test_email' , 
    @subject = 'Sample Data', 
    @attach_query_result_as_file = 1 ; 

它給了我下面的錯誤:

Msg 15281, Level 16, State 1, Procedure sp_send_dbmail, Line 0
SQL Server blocked access to procedure 'dbo.sp_send_dbmail' of component 'Database Mail XPs' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'Database Mail XPs' by using sp_configure. For more information about enabling 'Database Mail XPs', see "Surface Area Configuration" in SQL Server Books Online.

是否有任何其他方式做到這一點?

+7

我覺得這裏的錯誤信息實際上很有幫助。您是否嘗試與您的DBA檢查以啓用所需的SQL Server組件來發送電子郵件? – dcp

回答

3

沒有其他的方式使用DBMail我害怕。數據庫郵件需要啓用: EXEC sp_configure'數據庫郵件XPs',1 但是,另外,數據庫郵件需要配置一個適當的配置文件和帳戶。

解決方法1:我用於策略不啓用郵件的服務器是讓存儲過程調用運行查詢併發送電子郵件的SSIS包。這完全繞過了數據庫郵件,並且SSIS包與SMTP服務器建立了自己的連接。

我通常設置的方法是運行sp_startjob調用服務器代理作業,然後運行SSIS包。

希望這會有所幫助。

皮特

相關問題