Quantcast
Channel: SQL Service Broker forum
Viewing all 461 articles
Browse latest View live

Error queuing message - Cannot execute as the database principal because the principal "dbo" does not exist

$
0
0
CREATE QUEUE dbo.MyAuditQueue WITH STATUS=ON
,ACTIVATION
(
STATUS = OFF
,MAX_QUEUE_READERS = 1
,PROCEDURE_NAME = [MyAuditMessageDequeue]
,EXECUTE AS OWNER
)

Created a new service broker queue and tried to send it a message.  Ran a profiler trace to see what was going wrong and noticed this error message in profiler:

"An exception occurred while enqueueing a message in the target queue. Error: 15517, State: 1. Cannot execute as the database principal because the principal "dbo" does not exist, this type of principal cannot be impersonated, or you do not have permission."

What am I doing wrong?

Service Broker 2014


Error With Service Broker

$
0
0

Good Morning Forum

This morning the SQL Server logs had the following message 775 times: -

Service Broker needs to access the master key in the database 'DATABASE NAME'. Error code:26. The master key has to exist and the service master key encryption is required

The database in question does have Service Broker enabled; does anyone know what could be causing this error?


Please click "Mark As Answer" if my post helped. Tony C.

Communication Error

$
0
0

We have below error which made website down, 

A transport-level error has occurred when receiving results from the server. (provider: TCP Provider, error: 0 - The specified network name is no longer available.)

Select The Name, Date created and Message Count for all Service Broker Queues

$
0
0

Hello Forum

Is the a TSQL Statement that can select this data?  I'm currently collating all the stats for Service Broker, but in just one database I have over 70 Queues.


Please click "Mark As Answer" if my post helped. Tony C.


SQL Server Agent Job Custom Notifications

$
0
0

Is there a good way to customize sql agent notifications.  Not a fan of email or pager notifications.  More specifically, we use service broker and hipchat alot.  Would be nice if Service Broker could subscribe to the notifications.  If that is somehow possible we could send a corresponding message to hipchat.

SQL2014

Cannot start SQL Server Service Broker on Database Could not start Service Broker for database id: 13

$
0
0

Dear Team,

I am getting below error in event log

Cannot start SQL Server Service Broker on Database Could not start Service Broker for database id: 13

could you please help me to understand what does the above error mean and how can we resolve it.

Appreciate your input.

Regards

ChetanV

queue processing metrics

$
0
0

Does Service Broker provide any metrics or dmv's to monitor the average time of a message in a queue?

sql 2014

TSF 2015 configuration error

$
0
0

Hi,

I began configuring TFS 2015 and the SQL Server database(s), and ran into this error below

1 error(s) occurred while executing WorkItemTrackingCreateFullTExtIndex.sql script.

Failed batch starts on line: 1.

Error: 2115, Level: 16, State:1, Batch Line: 1, Script Line: 1

Message: Server level event notifications are disabled as the database msdb does not exist.

When I logon the SQL server, I see the msdb database exists there and the account I use has sysadmin privileges and I can access it.

Thanks,

Anna


TFS 2015 configuration error

$
0
0

Hi,

I began configuring TFS 2015 and the SQL Server database(s), and ran into this error below

1 error(s) occurred while executing WorkItemTrackingCreateFullTExtIndex.sql script.

Failed batch starts on line: 1.

Error: 2115, Level: 16, State:1, Batch Line: 1, Script Line: 1

Message: Server level event notifications are disabled as the database msdb does not exist.

When I logon the SQL server, I see the msdb database exists there and the account I use has sysadmin privileges and I can access it.

Thanks,

Anna


Service broker error handling / transaction rollback

$
0
0

We have a service broker activation sp for an auditing service that we are in the process of testing. Our QA purposefully en-queued a message with a bad XML element so it fails during the XML parsing process (does not get to the point of inserting an audit record).  In our catch block, we attempt to do a rollback to the save point after the message is received (so it won't be re-queued and eventually poison the queue) but sql gives us the following error when we do this:

"The current transaction cannot be committed and cannot be rolled back to a save-point. Roll back the entire transaction."

Why does SQL prevent us from rolling back to the save point in this instance?  Is there a good workaround?

ALTER PROCEDURE [dbo].[ImageAuditMessageDequeue]
AS

  SET NOCOUNT ON;

  DECLARE @RecvReqDlgHandle UNIQUEIDENTIFIER;
  DECLARE @RecvReqMsg varbinary(max);
  DECLARE @RecvReqMsgName sysname;
  declare @payload xml;

  DECLARE @ErrorNumber AS INT;
  DECLARE @ErrorMessage as nvarchar(4000);
  DECLARE @ErrorLine as int;
  DECLARE @ErrorProcedure as nvarchar(128);
  DECLARE @ErrorState as int;
  DECLARE @ErrorSeverity as int;
  DECLARE @EventMessage as VARCHAR(MAX);

  WHILE (1=1)
  BEGIN

    BEGIN TRANSACTION;

    WAITFOR
    ( RECEIVE TOP(1)
        @RecvReqDlgHandle = conversation_handle,
        @RecvReqMsg = message_body,
        @RecvReqMsgName = message_type_name
      FROM ImageAuditQueue
    ), TIMEOUT 5000;

    IF (@@ROWCOUNT = 0)
    BEGIN
      ROLLBACK TRANSACTION;
      BREAK;
    END

SAVE TRANSACTION MessageReceivedSavePoint

select @payload = cast(@RecvReqMsg as xml);

    IF @RecvReqMsgName = N'http://schemas.foo.com/messages/ImageAudit/Insert'
    BEGIN
BEGIN TRY
--Ugh, SQL XQuery will return 0 (instead of null) for empty node values that are declared as int so we must workaround this to coerce a null value for empty nodes
declare @companyId as int = cast(nullif(@payload.value('(/Root/ImageAudit/CompanyID)[1]', 'varchar(25)'), '') AS int);

declare @appId as int = @payload.value('(/Root/ImageAudit/AppID)[1]','int');  --error raised here due to bad xml value in message
declare @batchId as char(6) = @payload.value('(/Root/ImageAudit/BatchID)[1]','char(6)');

declare @imageId as int = cast(nullif(@payload.value('(/Root/ImageAudit/ImageID)[1]', 'varchar(25)'), '') AS int);
declare @docId as int = cast(nullif(@payload.value('(/Root/ImageAudit/DocID)[1]', 'varchar(25)'), '') AS int);
declare @docAge as int = cast(nullif(@payload.value('(/Root/ImageAudit/DocAgeInDays)[1]', 'varchar(25)'), '') AS int);

declare @currentDateTime as datetime = @payload.value('(/Root/ImageAudit/CurrentDateTime)[1]','datetime');

declare @userId as int = @payload.value('(/Root/ImageAudit/UserID)[1]','int');
declare @action as varchar(25) = @payload.value('(/Root/ImageAudit/Action)[1]','varchar(25)');

declare @seconds as float = cast(nullif(@payload.value('(/Root/ImageAudit/Seconds)[1]', 'varchar(25)'), '') AS float);

declare @additionalInfo as varchar(max) = @payload.value('(/Root/ImageAudit/AdditionalInfo)[1]','varchar(max)');

INSERT INTO FOTNAudit.dbo.ImageAuditDaily
(AppID, BatchID, ImageID, DocID, CurrentDateTime, UserID, Action, Seconds,CompanyID, DocAgeInDays, AdditionalInfo)
VALUES 
(@appId, @batchId, @imageId, @docId, @currentDateTime, @userId, @action, @seconds, @companyId, @docAge, @additionalInfo)

END CONVERSATION @RecvReqDlgHandle;
END TRY
BEGIN CATCH
-- We do not want to allow a message insertion to fail 5 consecutive times otherwise we risk the queue being stopped / poisoned.
--Because of this we implement our own error handling that simply logs the error and ends the conversation.
--This SHOULD prevent failed insertions from ever poisoning the queue.
SET @ErrorNumber = ERROR_NUMBER();
SET @ErrorSeverity = ERROR_SEVERITY();
SET @ErrorState = ERROR_STATE();
SET @ErrorProcedure = ERROR_PROCEDURE();
SET @ErrorLine = ERROR_LINE();
SET @ErrorMessage = ERROR_MESSAGE();    

SET @EventMessage = CONVERT(VARCHAR(MAX), @payload);
EXEC xp_logevent 60000, @EventMessage, ERROR; --this guy is not transactional so don't need to worry about logevent rollback

PRINT '@EventMessage = ' + @EventMessage
PRINT '@ErrorMessage = ' + @ErrorMessage

--Roll back transaction to the point that message has been deqeued but not processed
--to avoid potential queue poisoning
--This is where encounter the following error:
--"The current transaction cannot be committed and cannot be rolled back to a savepoint. Roll back the entire transaction."
            rollback transaction MessageReceivedSavePoint;        

            --end conversation @RecvReqDlgHandle with error = @ErrorNumber description = @ErrorMessage; 

--No real benefit in signaling a failure to sender so we just end the conversation      
END CONVERSATION @RecvReqDlgHandle;              
END CATCH;
    END
    ELSE IF @RecvReqMsgName = N'http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog'
    BEGIN
       END CONVERSATION @RecvReqDlgHandle;
    END
    ELSE IF @RecvReqMsgName = N'http://schemas.microsoft.com/SQL/ServiceBroker/Error'
    BEGIN
--Handling Service Broker Error Messages 
--https://technet.microsoft.com/en-us/library/ms171599(v=sql.105).aspx
--Log an error to the sql server log file and event viewer
SET @EventMessage = CONVERT(VARCHAR(MAX), @RecvReqMsg);
EXEC xp_logevent 60000, @EventMessage, ERROR;

PRINT '@EventMessage = ' + @EventMessage

END CONVERSATION @RecvReqDlgHandle;
    END

    COMMIT TRANSACTION;

  END

SQL2014

         

Subscribing to BROKER_QUEUE_DISABLED for entire server?

$
0
0

Is it possible to subscribe to BROKER_QUEUE_DISABLED for all queues on the server regardless of database?  If so, what is the correct TSQL syntax for the registration command?

I tried this but received an error:

CREATE EVENT NOTIFICATION QueueDisabledNotification
    ON SERVER
WITH FAN_IN
    FOR BROKER_QUEUE_DISABLED
    TO SERVICE 'DisabledQueueNotificationService', 'current database';

"The specified event type(s) is/are not valid on the specified target object."

sql 2014

Frequent service broker logon errors

$
0
0

I am seeing this error every few minutes in sql error log

[i]04/20/2016 17:06:01,Logon,Unknown,Service Broker login attempt by user 'domain\serviceuser.' failed with error: 'A previously existing connection with the same peer was detected during connection handshake. This connection lost the arbitration and it will be closed. All traffic will be redirected to the previously existing connection. This is an informational message only. No user action is required. State 80.'.  [CLIENT: 192.168.50.74][/i]

The environment is a four node WSFC with three SQL Server 2012 SP3 enterprise instances.  Under normal circumstances the SQL server roles run on distinct cluster nodes.  The physical cluster nodes have IP addresses 192.168.50.71 - 74 and the WSFC network resources have IP addresses 192.68.50.81 - 83.  Each instance is configured to use a static port 50101 - 50103

On each instance service broker is sending messages to another instance.  I see the above error in the SQL error log for all of the instances.  Each service broker endpoint is configured to listen on all IPs and has port 4022 configured.  The routes addresses are configured as TCP://SQLClusterResourceName:4022.

I made some profiler traces and saw a couple of other errors like "This message could not be delivered because it is duplicate" and
"An error occurred while receiving data: '64(The specified network name is no longer available.)" occurring occasionally.

I'm new to service broker, the initial configuration was done by somebody else, but from doing a lot of web searches it seems that the ACK may not being received by the initiator which cause the message to be resent which is why it's a duplicate, as mentioned here

social.msdn.microsoft.com/Forums/sqlserver/en-US/91747a32-f221-4d98-990f-af1606ca5c3c/this-message-could-not-be-delivered-because-it-is-duplicate?forum=sqlservicebroker


I found this old post which sounds very similar but unfortunately there's no resolution there.

social.msdn.microsoft.com/Forums/sqlserver/en-US/7cc67a9e-c792-4211-9f17-7dd3c6caf47c/service-broker-error-connection-handshake-failed?forum=sqlservicebroker

I have tried using the FQDN of the SQL cluster resource in the SB route and forcing the listener to the IP address of the cluster resource instead of all.  I also suspected a network issue but have found no other symptoms to support that.  I have tried disabling some of the more exotic NIC features, TCP offload, RSS etc.  Nothing I tried has made the slightest difference so far.

One thing that surprises me is that the client specified in the error message sometimes has the IP address of the physical cluster node and sometimes the SQL cluster resource IP address, the instances are definitely only listening on the cluster resource IP address, but the service broker can send using either.  Is that correct?  Is there a way to force all SQL communication to only send on the virtual server IP?

I tried to uses ssbdiagnose here is the output:

C:\Windows\system32>ssbdiagnose -E RUNTIME -NEW connect to -S server1\instance1 -d dbname1 connect to -S server2\instance2 -d dbname2
 
Microsoft SQL Server 11.0.2100.60
Service Broker Diagnostic Utility
P  29830                                 Could not find the connection to the SQ
L Server that corresponds to the routing address tcp://192.168.50.72:4022. Ensure
 the tool is connected to this server to allow investigation of runtime events
P  29830                                 Could not find the connection to the SQ
L Server that corresponds to the routing address tcp://192.168.50.73:4022. Ensure
 the tool is connected to this server to allow investigation of runtime events
P  29830                                 Could not find the connection to the SQ
L Server that corresponds to the routing address tcp://192.168.50.74:4022. Ensure
 the tool is connected to this server to allow investigation of runtime events
P  29830                                 Could not find the connection to the SQ
L Server that corresponds to the routing address tcp://192.168.50.71:4022. Ensure
 the tool is connected to this server to allow investigation of runtime events
An internal exception occurred: Access is denied. (Exception from HRESULT: 0x800
70005 (E_ACCESSDENIED))
^C

Can anyone help?  Where should I go from here?


MAX_QUEUE_READERS and Activated Procedures

$
0
0

If I set MAX_QUEUE_READERS =1 for a given queue, am I guaranteed to only ever have one instance of the associated activated stored procedure running at any time? I've run into an issue where it appears that more than one instance of the activated stored procedure is running even though MAX_QUEUE_READERS =1. The code was not designed to run multiple instances concurrently.

Thanks in advance.

SqlDependency.Stop method does not cancel the notification subscription in SQL Server 2012

$
0
0

On a .NET web app, we are using ChangeMonitor to update caches on data change at SQL Server 2012 database. And change monitor relies onSqlDependency.

When you call the SqlDependency.Stop method, the method does not actually cancel the notification subscription. When SQL Server sends a new query notification to the application, SQL Server cannot find the remote service. Therefore, error messages are logged. And we have a concern that this add more noise to the SQL log and trying to avoid.

There is a kb article for this for SQL Server 2005 and 2008. Actually its not a fix but workaround for not logging the error in SQL Log with use of trace flag 4133. https://support.microsoft.com/en-sg/kb/958006

1. Is there a fix for this for SQL Server 2012?

2. Is it recommended to use this trace flag(4133) for SQL Server 2012, wouldn't it prevent the genuine error messages?

Thanks for your support

Problems with sending Event Notifications to remote service

$
0
0

Hi!

 

Just set up my first Service Broker test. Wanted to send an Event Notification from one instance to another. Finally, the message arrives but profiler shows that the message is still being continously resent (and rejected as being duplicate). What am I doing wrong?

 

With best regards,

Artus

--

/* Local Event Source.sql */

USE master
GO

CREATE DATABASE NotificationDB
GO

ALTER DATABASE NotificationDB SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
GO

CREATE ENDPOINT BrokerEndpoint
STATE = STARTED
AS TCP
(
 LISTENER_PORT = 5554
)
FOR SERVICE_BROKER
(
 AUTHENTICATION = WINDOWS,
 ENCRYPTION = DISABLED
)
GO

USE NotificationDB
GO

CREATE EVENT NOTIFICATION TestEN
ON DATABASE
FOR CREATE_TABLE
TO SERVICE 'ExpressService', 'AFEDD339-AD3D-4865-AF3C-299B0A0784C6'
GO

CREATE ROUTE ExpressRoute
WITH SERVICE_NAME = 'ExpressService' ,
BROKER_INSTANCE = 'AFEDD339-AD3D-4865-AF3C-299B0A0784C6',
ADDRESS = 'TCP://localhost:5555'
GO

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Pa$$w0rd';
GO
 
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY;
GO

USE master
GO

SELECT service_broker_guid FROM sys.databases WHERE database_id = DB_ID()
GO

 

/* Remote Service.sql */

USE master
GO

CREATE DATABASE Test
GO

ALTER DATABASE Test SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE;
GO

CREATE ENDPOINT BrokerEndpoint
STATE = STARTED
AS TCP
(
 LISTENER_PORT = 5555
)
FOR SERVICE_BROKER
(
 AUTHENTICATION = WINDOWS,
 ENCRYPTION = DISABLED
)
GO

USE Test
GO

CREATE QUEUE ExpressQueue
WITH STATUS = ON
GO

CREATE SERVICE ExpressService
ON QUEUE ExpressQueue
(
 [http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]
);
GO 

GRANT SEND ON SERVICE::ExpressService
TO [public]
GO

CREATE ROUTE ExpressServiceRoute
WITH SERVICE_NAME = 'ExpressService',
BROKER_INSTANCE = 'AFEDD339-AD3D-4865-AF3C-299B0A0784C6',
ADDRESS = 'LOCAL'
GO 

CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'Pa$$w0rd';
GO
 
ALTER MASTER KEY ADD ENCRYPTION BY SERVICE MASTER KEY;
GO

SELECT service_broker_guid FROM sys.databases WHERE database_id = DB_ID()
GO

SELECT * FROM sys.endpoints
GO


Event Notification Configuration for a Remote Server

$
0
0

Hi, 

I am trying to configure Event Notification in such a way that all the Notification will be sent to a centralized server. Thus if any one can share the script to create the Event Notification for remote server. It will be of great help.

Thanks in Advance 

Francis

Required permissions for sending a message from service A to service B?

$
0
0

We have a windows service running as an AD user invoking an SP to send a message from service A to service B.

If I run the sp, it works fine.  If the service user runs the sp, the sp blows up with this error:

Cannot find the object "StatsMonitor" because it does not exist or you do not have permissions.

StatsMonitor is the target queue in this case.

Here is the code in the sp that blows up:

SET @Handle = NEWID()
		BEGIN DIALOG CONVERSATION @Handle
		FROM SERVICE StatsMonitorPublisher
		TO SERVICE 'StatsMonitorSubscriber'
		ON CONTRACT [http://schemas.foo.com/contracts/StatsMonitor]
		WITH ENCRYPTION = OFF;
		SEND ON CONVERSATION @Handle
		MESSAGE TYPE [http://schemas.foo.com/messages/StatsMonitor/MonitorNow](@MessageBody);
		END CONVERSATION @Handle

		if @debug = 1
		begin
			print 'StatsMonitor message sent!'
			print CONVERT(VARCHAR(MAX), @MessageBody, 1);
		end

I tried the following but it didn't seem to help:

GRANT SEND ON SERVICE::[StatsMonitorPublisher]
TO [foo\devservice] ;

 Please advise.

thanks

External Activator Connected to Availiability Group Listener

$
0
0

I am having a problem getting the Service Broker External Activator (SBEA) working when pointed to an Availability Group Listener.  If I point SBEA directly to the primary replica then it functions properly.  The issue with that setup is when an automatic fail over occurs SBEA will stop being able to process messages as the database will then be in a Read-Only state (see error message below):

5/26/2016 7:54:30 AM  EXCEPTION         ERROR = 90, Internal exceptions have occurred when External Activator is receiving event notifications.

5/26/2016 7:54:30 AM  EXCEPTIONDETAILS         Inner Exception:

5/26/2016 7:54:30 AM  EXCEPTIONDETAILS         System.Data.SqlClient.SqlException: Failed to update database "ServiceBrokerNotification"because the database is read-only.

Does anyone know if there are any special considerations or documentation available for configuring SBEA with an Availability Group Listener?

Service Broker + AAG(Synchronous) + Listener

$
0
0

Hi everyone!

I've make a test environment with 3 servers:
"Comp2" and "Comp3" servers host AlwaysOn Availability Group with Listener in Synchrounos Mode. "Comp2" - primary replica, "Comp3" - secondary replica
"Comp1" server hosts Service Broker with route on AAG Listener

In this environment I send simple messages by Service Broker from "Comp1" (Service Broker host) to "Comp2" (primary replica AAG).
It works good: messages are transmitted fast, in proper order and so on.
Then I make a failover on "Comp2", so primary replica moves to "Comp3", and I've got 2 cases:

1. There is no problem with transmitting of Service Broker messages, if Initiator's sys.transmission_queue is empty
In this case existing conversation handles works fine: messages are transmitted to "Comp2" correctly

2: If there are messages in Initiator's sys.transmission_queue in moment of a failover ("Comp2" -> "Comp3") then I've got a problem with transmitting Service Broker messages from "Comp1" to "Comp3".
These messages and all new messages sent in existing conversation handle aren't transmitted to "Comp3", so sys.transmission_queue on "Comp1" grows. 

Have you any idea what's the problem?

Microsoft SQL Server 2014 (SP1-CU6-OD) (KB3167392) - 12.0.4457.0 (X64)   May 26 2016 23:44:09   Copyright (c) Microsoft Corporation  Enterprise Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: )


http://www.t-sql.ru


Connecting to the Always On Listener

$
0
0

Hello,

We have a listener configured for our 2012 AlwaysOn configuration.  We also have a service broker process (SQL 2012) that connects to the listener to add data to the AlwaysOn instance. 

If we use a fully qualified listener name in the route, we only connect sporadically on the failover nodes.  Does Service Broker require a net bios connection?  Our network team is not wild about this.  The net bios connection, however is dependable after failover.

Does service broker require a restart after a failover?  Is this the issue?

We are new to service broker.  Any help appreciated.

Dianne


Dianne

Viewing all 461 articles
Browse latest View live