I am unable to send a Service Bus Message from Sql Server with a newly set up credential and queue

Spencer Thompson (Network) 0 Reputation points
2025-09-24T10:09:20.54+00:00

I setup a new queue using the same code as before and I cannot actually send a message:

56D2B880-4278-4DB8-AE34-84916885E475 {"response":{"status":{"http":{"code":401,"description":"SubCode=40100: Unauthorized : Unauthorized access for 'Send' operation on endpoint 'sb://netservice.servicebus.windows.net/netservice-portaljobupdates/messages'. Tracking Id: 6e89c3f5-095a-475a-a839-c651f4673cb8_G15"}},"headers":{"HTTP/1.1 401 SubCode=40100":"Unauthorized : Unauthorized access for 'Send' operation on endpoint 'sb://netservice.servicebus.windows.net/netservice-portaljobupdates/messages'. Tracking Id: 6e89c3f5-095a-475a-a839-c651f4673cb8_G15","Date":"Wed, 24 Sep 2025 10:02:00 GMT","Content-Length":"0","Server":"Microsoft-HTTPAPI/2.0","Strict-Transport-Security":"max-age=31536000"}}}

The code I used was figured out here and definitely worked because I have Service Bus messages being sent ok that I set up using the code.

https://free.blessedness.top/en-us/answers/questions/1792292/unable-to-send-message-from-azure-sql-to-service-b

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
{count} votes

1 answer

Sort by: Most helpful
  1. Sina Salam 26,081 Reputation points Volunteer Moderator
    2025-09-25T10:15:26.2933333+00:00

    Hello Spencer Thompson (Network),

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are unable to send a Service Bus Message from Sql Server with a newly set up credential and queue.

    The below should solve the issue:

    1. Open Master Key:
      OPEN MASTER KEY DECRYPTION BY PASSWORD='<yourPassword>';
    
    1. Create Scoped Credential:
    CREATE DATABASE SCOPED CREDENTIAL [https://<serviceBusName>.servicebus.windows.net/<queueName>]
       WITH IDENTITY = 'Managed Identity',
       SECRET = '{"resourceid":"https://servicebus.azure.net"}';
    
    1. Send Message:
      DECLARE @response NVARCHAR(MAX);
       DECLARE @url NVARCHAR(4000) = N'https://<serviceBusName>.servicebus.windows.net/<queueName>/messages';
       DECLARE @Guid NVARCHAR(40) = NEWID();
       DECLARE @payload NVARCHAR(MAX) = '{ "message": "Hello, world! ' + @Guid + '" }';
       EXEC sp_invoke_external_rest_endpoint
           @method = N'POST',
           @url = @url,
           @credential = [<serviceBusName>.servicebus.windows.net/<queueName>],
           @payload = @payload,
           @response = @response OUTPUT;
       PRINT @Guid + ' ' + @response;
    

    I hope this is helpful! Do not hesitate to let me know if you have any other questions or clarifications.


    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.