@Query Parameter in sp_send_dbmail???

  • Howzit everyone,

    As I am a little new to SQL 2005 any help on this relatively simple matter would be gretaly appreciated.

    I am trying to run a simple sp_send_dbmail proc with an @Query parameter. When the proc runs I get the following error:

     

    Msg 22050, Level 16, State 1, Line 0

    Failed to open loopback connection. Please see event log for more information.

     

    Anyone have any ideas as to how I can fix this????

     

    Thanks in advance

     


    gex

  • Gex,

    Can you post your statement plz. It's hard to tell what's wrong without knowing your exact statement. Personally I don't have any problems using the @query parameter.

    Markus

    [font="Verdana"]Markus Bohse[/font]

  • Hi Markus,

     

    Here is the Query :

    EXECUTE

    msdb.dbo.sp_send_DBmail

      @Profile_name

    = 'DB_Mail'

    , @recipients = 'Name@Domain.co.za'

    , @subject = 'Daily Reports: MIS Collections Step 1 has Completed'

    , @Body = 'Daily Reports: tbl_HSReports has been uploaded.'

    , @query = 'Select * From MIS.dbo.MIS_Log'

     

     


    gex

  • The statement looks good to me. Can you send any other mails with db mail ? Is the profile configured correctly ? Try sending a testmail.

    Markus

    [font="Verdana"]Markus Bohse[/font]

  • Even i am receiving the same

    Failed to open loopback connection. Please see event log for more information..

    did u resolve the same? Please let me know how did u resolve it.

     

     

  • We had this kind of problem. Try putting your select statement in parenthesis.

    I'm not exactly sure why that should help, but it did for us.

  • I am having the same problem with a local sql server 2005 standard edition.

  • Hi,

    This error will occur when the mail size is too large. Consider in this case if the statement "Select * From MIS.dbo.MIS_Log" returns a large number of rows then automatically the size of the mail will be increased, hence pls use where condition to shorten the select statement or you can also use top() so that the mail can be split into several parts

    PS: I'm not sure about this, i heard that this has been fixed in the latest release of sql server service pack. So try installing SQL server SP2 with critical update.

  • This may or may not help, and sounds nuts, but, I ran into this same problem on Server 2008 with SQL 2008. And the problem was caused by ORACLE!

    Yes, I said ORACLE!

    I installed Oracle, and following their setup directions, added a loop-back adapter AND an entry in my hosts file.

    My Host Name is GALAXY and per Oracle, I needed to set a dummy network connection and add an entry in the hosts file similar to:

    127.0.0.1 localhost

    10.10.10.10 galaxy.domain.home GALAXY #loopback adapater

    Because of this, when SQL Server Agent tried to connect to the "local" instance (ie: Galaxy) it wasn't resolving.

    I fixed it by updating the hosts file to read as follows:

    127.0.0.1 localhost GALAXY

    10.10.10.10 galaxy.domain.home #loopback adapater

    Once I did this and rebooted, all was well for SQL!

    What lead me to this was the fact that I couldn't see any of the SQL Server Errorlogs. Open SSMS, connect to the local server, click on Management- SQL Server Logs

    and you get the error: Failed to retrieve data for this request.

    and you will be unable to see the list of SQL errorlogs. If you open a query window and run the stored proc xp_enumerrorlogs you will get the error/message:

    Msg 22004, Level 16, State 1, Line 0

    Failed to open loopback connection. Please see event log for more information.

    Msg 22004, Level 16, State 1, Line 0

    error log location not found

    Once I saw "Failed to open loopback conncetion...." Ah ha! Check the hosts file!

    So I did. Changed it as stated above, and MS SQL 2008 was up and running...

    But, I'm not sure if my Oracle 10g installation will be happy. It's up, and I can connect with OraEM, but, what else will go wrong?

    Maybe someday...Gates & Ellison will learn to play nice together....

    Until then, let the DBAs and Network Trolls fight the good fight..

    Don't take any wooden data!

    Sincerely, Smm3SQL

  • I have found that I get this error when I connect to my local instance of SQL Server but am on a network outside of my domain. It is resolved when I VPN to my network. This might be related to the inability to use linked servers in the same circumstances (which can also be resolved via VPN) as described here http://blogs.msdn.com/sql_protocols/archive/2005/10/19/482782.aspx.

  • Hello,

    I am having the same problem on newly installed Sql server 2008 R2.

    Can some one please let me know how to solve this?

    I have even tried with host file solution too. But it didn't worked for my case. 🙁

    Thanks,

    Jatin Soni

  • Found the issue....

    By mistake I have added an Alias as <same server name> and <IP> entry using sql server configuration manager which was pointing to same server. You dont need an alias for the same server, however I missed that point and created alias which was somehow causing Loopback Error when using @query parameter.

  • Thanks for posting the answer to what your own fix was. It's sure to help some other folks.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 13 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic. Login to reply