Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8821103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:46:16+00:00 2026-06-14T05:46:16+00:00

I have a procedure that pulls data from my database and uses MSDB.DBO.sp_send_dbmail to

  • 0

I have a procedure that pulls data from my database and uses MSDB.DBO.sp_send_dbmail to send out e-mails. The procedure itself runs without a hitch when I use ‘EXEC myprocedure’. But when I set up a job for the procedure, the job fails with the following error

‘Error formating query, probably invalid parameters [SQLState
42000](Error 22050). The step failed’

There is one step in the job with the TSQL statement ‘EXEC myprocedure’, using the database that my procedure is stored on. Does anyone know what could be causing this error?

Update

I’ve narrowed the problem down. It’s something with the Exchange server I use. I was using a domain address (ie. mail.mycompany.com) as the ‘Server name’ under Database Mail’s account configuration wizard. I was unable to send e-mails to listservs and external users using this domain address. I talked to our Exchange guy and he recommended using the actual IP address of one of the mail servers (ie. 10.123.53.53). That fixed the problem with listservs and external users, but now I am unable to send e-mails when I run my procedure using a job (the procedure itself executes properly when I manually run it). Does anyone know what criteria on our Exchange server I will need to change to fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:46:17+00:00Added an answer on June 14, 2026 at 5:46 am

    The problem was with the @query parameter used by sp_send_dbmail. For some reason, my SQL Server Agent account (which was a domain administrator) was denied access to use sp_send_dbmail with the @query parameter. I ended up dropping the @query parameter altogether and putting everything in the @body parameter. The @body parameter became a concatenation of regular text and what returned from a SELECT query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that pulls data for a report. I'm having a
I have a stored procedure that pulls data for a SS Report. I need
I have a page that pulls together aggregate data from two different tables. I
In a part of my data warehousing stored procedures, i have a procedure that
I have a stored procedure that returns data in the format of: Date |
I have a stored procedure (that I didn't write) that uses openquery to populate
I have a stored procedure that uses a view to pull 6 averages. The
I have a MySQL 5 database that is updated every 5 minutes from a
I have a stored procedure that is called by data collection system . The
I have currently created a facebook like page that pulls notifications from different tables,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.