Home Forums Programming General Using a parameter in a procedure for sp_send_dbmail, the mail never gets received RE: Using a parameter in a procedure for sp_send_dbmail, the mail never gets received

  • Ok so I have similar problem.

    I have a package that reads a file processes it and inserts the data into a table, very simple.
    I have all that working, now I want to be notified if the package fails, I can get that to work, however getting the package name in the email, I haven't been able to do, I don't want to hard code the package name, otherwise I'd have one for each package.
    I am try to get the system variable passed to the stored procedure. Here's my stored procedure.  I have tried to set the Parameter mappings and setting the Result Set but it errors with sp expects param @PKG but was not supplied, any help would be appreciated. It's SQL2012, This is also in the event handler at package level, OnError

    CREATE PROCEDURE [dbo].[spSalesDataErrorsV2] @PKG VARCHAR(200)

    AS

    declare @recipients varchar(255)

    declare @subject varchar(255)

    EXEC msdb.dbo.sp_send_dbmail @recipients= 'abc@email.com',

    @subject = @PKG,----Currently I have the package name hard coded

    @body = 'The package failed'

    GO