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 6860699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:26:29+00:00 2026-05-27T02:26:29+00:00

In my application I need to call a Stored Proc Asynchronously. For this I

  • 0

In my application I need to call a Stored Proc Asynchronously.
For this I am using Sql Service Broker.
These are the steps Involved in creating the asynchronous calling.

1) I created Message,Contract,Queue,Service.
And Sending messages.I can see my messages in ‘ReceiveQueue1’.

2) I created a stored Proc and a Queue
When I execute the Stored Proc(proc_AddRecord) its executing only once.
Its reading all the records in the Queues and adding those records to the table.
Upto this point its working fine.
But when I add some new messages to ‘ReceiveQueue1’ my stored proc is not adding those
records automatically to the table. I have to re execute the Stored Proc(proc_AddRecord)
inorder to add the new messages. Why is the Stored proc is not getting executed.
What I am supposed to do in order to call the Stored Proc Asynchronously.
The whole point of using Service Broker is to call stored procs asynchronously.
I am totally new to SQL Server Service Broker.
Appreciate any help.
Here is my code for the stored Proc

#

--exec proc_AddRecord

ALTER PROCEDURE proc_AddRecord
AS

Declare
    @Conversation UniqueIdentifier,
    @msgTypeName nvarchar(200),
    @msg varbinary(max)

While (1=1)
Begin
    Begin Transaction;

    WAITFOR
    (
        Receive Top (1) 
            @Conversation = conversation_handle,
            @msgTypeName =  message_type_name,
            @msg = message_body
        from dbo.ReceiveQueue1
    ), TIMEOUT 5000


    IF @@Rowcount = 0
        Begin 
            Rollback Transaction
            Break
        End
    PRINT  @msg
    If @msg = 'Sales'
        BEGIN
            insert into TableCity(deptNo,Manager,Group,EmpCount) VALUES(101,'Reeves',51, 29)
            COMMIT Transaction
            Continue
        End
    If @msg = 'HR'
        BEGIN
            insert into  TableCity(deptNo,Manager,Group,EmpCount) VALUES(102,'Cussac',55, 14)
            COMMIT Transaction
            Continue
        End

    Begin
        Print 'Process end of dialog messages here.'
        End Conversation @Conversation
        Commit Transaction
        Continue
    End
    Rollback Transaction
END

ALTER QUEUE AddRecorQueue
WITH ACTIVATION (
                PROCEDURE_NAME=proc_AddRecord,
                MAX_QUEUE_READERS = 1,
                STATUS = ON,
                EXECUTE AS 'dbo');
  • 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-05-27T02:26:29+00:00Added an answer on May 27, 2026 at 2:26 am

    You say you are executing the stored procedure, you shouldn’t need to do that, not even once, it should always be done with the activation.

    Should your activation be on your ‘ReceiveQueue1’ instead of your ‘AddRecorQueue’ I can’t see the rest of your code, but the names suggest it.

    Where does your stored procedure begin and end? Generally I’d put BEGIN just after the AS statement and END where the stored procedure should end, If you don’t have these then you’d need a GO statement to separate it off. Otherwise your ALTER QUEUE statement would be part of the stored procedure

    You also have “Rollback Transaction” so even if the activation was working it would all get rolled back, or raise an error saying there was no transaction had one of the IF statements been triggered.

    I suggest you follow this tutorial for service broker in general and this one about internal activation. They should get you started.

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

Sidebar

Related Questions

I need to call some PL/SQL procedures from my Java application. I can do
I am creating a Console Application, in that I need to Call a Method,
I am using ajax call in my classic asp application to execute a stored
I am using LINQ-to-SQL for an application that queries a legacy database. I need
In fact, if I call the stored procedures from my application, I need a
I need to develop an application which can access an SQL Server database stored
On my MVVM Silverlight application I need to call Domain service function to get
Mending a bug in our SAP BW web application, I need to call two
I've an application where, for testing, I need to replace the time.time() call with
I need to run a stored procedure from a C# application. I use the

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.