如何在存储过程中禁用 sp_send_dbmail 用法

How to disable sp_send_dbmail usage in Store Procedures

我已经接管了一个写得不好的系统并执行了一个特定的存储过程,它似乎正在调用 sp_send_dbmail。目前我什至没有在存储过程中看到 sp_send_dbmail 被调用的地方。在这个阶段,我正在寻找一种方法来从商店程序以及它甚至被调用的地方永久禁用它。也许它只在存储过程出错时调用?如果是,那是在哪里设置的?

这是我的存储过程的样子:

USE [pis]
GO
/****** Object:  StoredProcedure [dbo].[deal_note]    Script Date: 4/15/2015 7:25:27 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[deal_note](
    @keycode        varchar(50),
    @deal_id        int,
    @notes          varchar(max)
) as
/*



    select * from dbo.consumernotes
*/
begin
    set nocount on
    --parse key and code
    declare @key            int
    declare @code           int
    select
        @key    = left(@keycode, charindex('-',@keycode)-1),
        @code   = substring( @keycode, charindex('-', @keycode)+1, len(@keycode) )

    declare @user_id        int

    select top 1
        @user_id        = k.[user_id]
    from acc.Keys k
    where k.id = @key
        and k.code = @code

    insert into dbo.ConsumerNotes 
        (deal_id, notes, created_by )
    select @deal_id, @notes, @user_id 

    if @@rowcount>0
        select '0' [code], 'note' [section], 'Record updated.' [message]
    else
        select '1' [code], 'note' [section], 'Error updating record..' [message]


end--procedure

您必须暂时停止您的数据库邮件,通过在过程开始时添加以下语句来执行此操作:

EXECUTE MSDB.dbo.sysmail_stop_sp

在该过程结束时,您需要再次启动数据库邮件,这可以通过以下方式完成:

EXECUTE MSDB.dbo.sysmail_start_sp