Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Send email from a stored procedure

Send email from a stored procedure

Scheduled Pinned Locked Moved Database
databasesharepointsql-serversysadminquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member 1284721
    wrote on last edited by
    #1

    I need to send an email from a stored procedure, I found I use msdb.sp_send_dbmail, can someone give a suggestion on how I can do it except calling this built-procedure in sql server? Thanks.

    G L C 4 Replies Last reply
    0
    • M Member 1284721

      I need to send an email from a stored procedure, I found I use msdb.sp_send_dbmail, can someone give a suggestion on how I can do it except calling this built-procedure in sql server? Thanks.

      G Offline
      G Offline
      GuyThiebaut
      wrote on last edited by
      #2

      I use sp_send_dbmail - I can't think of any other methods provided by sql server which will do this. For security reasons I have the stored procedure, which runs this, within the msdb database as certain permissions, which I am unwilling to give to users, are needed to run this stored procedure.

      “That which can be asserted without evidence, can be dismissed without evidence.”

      ― Christopher Hitchens

      M 1 Reply Last reply
      0
      • M Member 1284721

        I need to send an email from a stored procedure, I found I use msdb.sp_send_dbmail, can someone give a suggestion on how I can do it except calling this built-procedure in sql server? Thanks.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        The sproc is there to provide the functionality. If it is there, and works, and you need such, why ask for "any" solution that excludes it? Why "except"?

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • M Member 1284721

          I need to send an email from a stored procedure, I found I use msdb.sp_send_dbmail, can someone give a suggestion on how I can do it except calling this built-procedure in sql server? Thanks.

          C Offline
          C Offline
          Corporal Agarn
          wrote on last edited by
          #4

          You can always have a .NET program run the procedure taking data from it and email from the .NET program.

          1 Reply Last reply
          0
          • G GuyThiebaut

            I use sp_send_dbmail - I can't think of any other methods provided by sql server which will do this. For security reasons I have the stored procedure, which runs this, within the msdb database as certain permissions, which I am unwilling to give to users, are needed to run this stored procedure.

            “That which can be asserted without evidence, can be dismissed without evidence.”

            ― Christopher Hitchens

            M Offline
            M Offline
            Member 1284721
            wrote on last edited by
            #5

            thank you very much for your reply. Can you tell me what the best practice is for notifying an developer if an error occurred in a stored procedure?

            G J 2 Replies Last reply
            0
            • M Member 1284721

              thank you very much for your reply. Can you tell me what the best practice is for notifying an developer if an error occurred in a stored procedure?

              G Offline
              G Offline
              GuyThiebaut
              wrote on last edited by
              #6

              Just throw the exception. There is no reason, I can think of, that you should need to catch an exception from a stored procedure. Throwing the exception will allow the developer to have an error message and pursue fixing the error.

              “That which can be asserted without evidence, can be dismissed without evidence.”

              ― Christopher Hitchens

              1 Reply Last reply
              0
              • M Member 1284721

                thank you very much for your reply. Can you tell me what the best practice is for notifying an developer if an error occurred in a stored procedure?

                J Offline
                J Offline
                jschell
                wrote on last edited by
                #7

                Member 1284721 wrote:

                Can you tell me what the best practice is for notifying an developer if an error occurred in a stored procedure?

                What happens if the stored proc doesn't run at all?

                1 Reply Last reply
                0
                • M Member 1284721

                  I need to send an email from a stored procedure, I found I use msdb.sp_send_dbmail, can someone give a suggestion on how I can do it except calling this built-procedure in sql server? Thanks.

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Please read here Try Catch in SQL - Reporting stored procedure error in email and also log the error in a table[^] You can see an error mechanism also in that link. Cheers :)

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups