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

SSBS External Activation Event Notification Server Alias

$
0
0

Hi There,

I am using External Activation on SQL Server 2008 R2.

In the ExternalActivatorQueue we have the following message,

<EVENT_INSTANCE>

  <EventType>QUEUE_ACTIVATION</EventType>

  <PostTime></PostTime>

  <SPID>777</SPID>

 <ServerName>TestServer</ServerName>

  <LoginName>MyLogin</LoginName>

  <UserName>dbo</UserName>

  <DatabaseName>MyBroker</DatabaseName>

  <SchemaName>dbo</SchemaName>

  <ObjectName>MyQueue</ObjectName>

  <ObjectType>QUEUE</ObjectType>

</EVENT_INSTANCE>

The ServerName is the SQL Server Name and in the EAService.config file,

the ServerName has to match.

<ApplicationServiceList>
    <ApplicationService name="MyService" enabled="true">
      <OnNotification>
       <ServerName>TestServer</ServerName>
        <DatabaseName>MyBroker</DatabaseName>
        <SchemaName>dbo</SchemaName>
        <QueueName>MyQueue</QueueName>
      </OnNotification>

The question we have is, is it possible to set the ServerName in the OnNotification tag within the EAService.config to an alias?

This can already be done in the SQL connection within the EAService.config

 <NotificationService name="MyService" id="999" enabled="true">
      <Description>My Test</Description>
      <ConnectionString>

       <Unencrypted>server=NetworkServerAlias;database=MyBroker;Application Name=My External Activator Service DB;Integrated Security=true;</Unencrypted>
      </ConnectionString>
    </NotificationService>
 

Which I guess would mean the ServerName in the Event Instance would need to change to.


Cheers


Transaction Log Filling the Disk

$
0
0

I am having an issue with the transaction growing uncontrolled and filling up the disk. I suspect that transactions are structured incorrectly between the web application that is monitoring a queue and the SQL that is executing the WAITFOR RECEIVE. This method is receiving large binary objects, so thats the reason for the arguments to the reader. Also, even though its not the suggested way, we commit everytime through to prevent the queue from disabling (which it was doing when we would ROLLBACK - we don't really care if the message is bad, we just want to log it and wait for the next one).

 

The basic structure is this, which is executed on a separate thread. Am I missing something that could be causing transactions to get into a state where the log grows uncontrollably? Is there a problem with the loop? Should I be doing a ROLLBACK when there is nothing to receive (this is a low volume queue, so it may not receive a message for a few minutes or more)? If so, where should I be doing this?

 

private

void MonitorUpdateQueue()

{

conststring _sqlEndDialog = @"END CONVERSATION @conversationHandle";

conststring _errorMessageType = @"http://schemas.microsoft.com/SQL/ServiceBroker/Error";

conststring _endDialogMessageType = @"http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog";

using (_ssbConnection)

{

if (_ssbConnection == null) _ssbConnection = new SqlConnection();

using (_monitorQueueCommand =

new SqlCommand("asp_ProcessMessage", _ssbConnection))

{

_monitorQueueCommand.CommandType = CommandType.StoredProcedure;

_monitorQueueCommand.CommandTimeout = 0;

while (true)

{

SqlDataReader reader =

null;

Guid conversationHandle = Guid.Empty;

Byte[] payloadBytes = { 0 };

try

{

if (_ssbConnection.State == ConnectionState.Closed)

{

_ssbConnection.ConnectionString = _ssbConnectionString;

_ssbConnection.Open();

}

Byte[] latestFullUpdate = null;

_monitorQueueCommand.Transaction = _ssbConnection.BeginTransaction(IsolationLevel.Serializable);

if (_monitorQueueCommand.Transaction != null)

{

reader = _monitorQueueCommand.ExecuteReader(CommandBehavior.SequentialAccess);

if (reader != null)

{

XmlDocument updateMessage =

new XmlDocument();

while (reader.Read())

{

conversationHandle = reader.GetGuid(0);

string messageType = reader.GetString(1);

payloadBytes = reader.GetSqlBytes(2).Value;

if (messageType == _endDialogMessageType || messageType == _errorMessageType)

{

SqlCommand cmdEndDialog =

new SqlCommand(_sqlEndDialog, _ssbConnection, _monitorQueueCommand.Transaction);

cmdEndDialog.Parameters.AddWithValue(

"@conversationHandle",

conversationHandle);

cmdEndDialog.ExecuteNonQuery();

}

else

{

if (payloadBytes.Length > 0)

{

ProcessUpdateQueue(updateMessage);

}

}

}

reader.Close();

}

_monitorQueueCommand.Transaction.Commit();

}

}

catch (Exception ex)

{

if (_monitorQueueCommand.Transaction != null&& _monitorQueueCommand.Transaction.Connection != null)

{

// Dequeue the bad message and ends the conversation

SqlCommand cmdQuarantineMessage =

new SqlCommand("usp_FailMessage", _ssbConnection, _monitorQueueCommand.Transaction);

cmdQuarantineMessage.CommandType = CommandType.StoredProcedure;

cmdQuarantineMessage.ExecuteNonQuery();

if (reader != null&& !reader.IsClosed) reader.Close();

if (_monitorQueueCommand.Transaction != null) _monitorQueueCommand.Transaction.Commit();

}

log.Error(

"Error monitoring queue.", ex);

}

finally

{

if (reader != null&& !reader.IsClosed) reader.Close();

if (_monitorQueueCommand.Transaction != null)

{

_monitorQueueCommand.Transaction =

null;

}

}

}

}

}

}

 

 

The stored procedure that is monitoring looks like this:

 

CREATE

PROCEDURE [dbo].[asp_ProcessMessage]

AS

BEGIN

WAITFOR(RECEIVETOP( 1 )conversation_handle, message_type_name, message_body

FROM [MyQueue] );

END

SQL Servic Broker Queue in Web Application

$
0
0
Hello friends,

  I want use SQL Service Broker Queue in Web Application where on server site i will have SQL Server 2005 install but on client site i want any ordinary system should be able to setup Service Broker communication with server. Is this possible to do so?

please  help me in this case ..............................

thank you,
santosh

far_principal_id in sys.conversation_endpoints table

$
0
0

Hi Everyone,

I have a bunch of conversations stuck in sys.transmission_queue and all of them have a far_principal_id=-1 in sys.conversation_endpoints. I don't get the significance of -1 in that column. What do I make of it? TIA


Mordechai Danielov

notify when message arrives

$
0
0

Using a stored procedure, message was created and sent to a queue. Then control was retun back to user to complete other task. Now, how would I know if there is a message arrived in the target queue? Do I need to run a service for this? Is there any inbuild mechanism in Service Broker?

Problem with sending mail via Database Mail

$
0
0

Hi every body


I want to send a simple mail using DATABASE MAIL feature in SQL SERVER 2005.

I've defined a public profile.
I've enabled Database Mail stored procedures through the Surface Area Configuration .

but   I can't send a mail with sp_send_dbmail stored procedure in 'msdb' database .


when I execute sp_send_dbmail in the Managment Studio  the message is
"Mail queued"  but the mail is not sent.

Could it be related to Service Broker?Because  the Surface Area Configuration indicates:'this inctance does not have a Service Broker endpoint'.If so, how should I make an endpoint?

here is the log file after executing sp_send_dbmail:


1)  "DatabaseMail process is started"

2)   "The mail could not be sent to the recipients because of the mail server failure. (Sending Mail using Account 2 (2007-03-08T00:49:29). Exception Message: Could not connect to mail server. (No connection could be made because the target machine actively refused it)."

 The DatabaseMail90.exe is triggred ,so the mail is transfered to the mail queue but  DatabaseMail90.exe couldn't give the mail to SMTP server.The promlem is what should I do to make DatabaseMail90.exe able to connect to  the server?



please help me.

POUYAN

activation stops working after a cluster failover

$
0
0

Hi All, 

I'm running into a problem with SSB on 

Microsoft SQL Server 2008 (SP1) - 10.0.2841.0 (X64) 
May 13 2011 12:08:08 
Copyright (c) 1988-2008 Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.0 <X64> (Build 6002: Service Pack 2)

after a cluster failover, activation doesn't work. Queues build up until I turn activation off and back on. Is this a bug or a feature?


Mordechai Danielov

Sort_warning notification

$
0
0

I would like to call procedure(which is empty for test) when sort warning is happened. I have enabled service broker, created a queue to receive messages, created a service on the queue that references the event notifications contract, and finally created an event notification. But when sort warning happens(I can see it in profiler), there is no message in queue and SP is not invoked. Have I missed something?

br, Simon

CREATE QUEUE dbo.SortWarningsQueue
WITH STATUS=ON,	
ACTIVATION 
			(
				PROCEDURE_NAME = dbo.process_sort_warning_event,
				MAX_QUEUE_READERS = 5,
				EXECUTE AS OWNER
			);

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

--Create the database event notification
CREATE EVENT NOTIFICATION NotifySort_Warnings
ON SERVER
FOR SORT_WARNINGS
TO SERVICE 'SortWarningsService','current database';
GO



sys.dm_broker_queue_monitors missing information after cluster failover

$
0
0

where does sys.dm_broker_queue_monitors get its information from? I see that it's created by

CREATE VIEW sys.dm_broker_queue_monitors AS
    SELECT * FROM OpenRowset (TABLE SBQUEUEMONITORS)

but can't seem to find information on SBQUEUEMONITORS. What is it?

On a more practical level. The reason why I am looking into this is because when I failover a SQL server 2008 SP3 cluster all entries associated with the user database disappear from this view. sys.service_queues shows that activation is on, but activation SP doesn't react to new messages. only when I turn the activation off and on with alter queue does the system view get re-populated and activation works again.

What could be the cause of this behavior?

Thanks.


Mordechai Danielov

Error log loaded with stack dumps and error messages

$
0
0

Our error log is filled with errors of this nature:

Error: 9646, Severity: 16, State: 2.

An error occurred in the timer event cache. Error 845, state 1.
Process 491:0:2 (0x184c) Worker 0x00000010754D2160 appears to be non-yielding on Scheduler 24. Thread creation time: 13020506683971. Approx Thread CPU Used: kernel 1248 ms, user 13594083 ms. Process Utilization 10%. System Idle 89%. Interval: 20353254 ms.

A time-out occurred while waiting for buffer latch -- type 2, bp 00000010ADB0AB00, page 1:240, stat 0x9, database id: 16, allocation unit Id: 281474981494784/4784128, task 0x0000000751019498 : 0, waittime 300 seconds, flags 0x3038, owning task 0x0000000000000000. Not continuing to wait.

As well as these:

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

Is it all resource related?

Thank you,

Mike


Error: 1222, State: 51. Lock request time out period exceeded. This is an informational message only. No user action is required.

$
0
0

Our production database upgrade from SQL Server 2008 R2 to SQL Server 2012 SP1 recently.

And the active tasks are still increasing, we have 690000 active tasks now.

find that many error message:

Date 8/18/2013 7:01:11 PM
Log SQL Server (Current - 8/18/2013 7:16:00 PM)
Source spid35s
Message
An error occurred in Service Broker internal activation while trying to scan the user queue 'Queue Name' for its status. Error: 1222, State: 51. Lock request time out period exceeded. This is an informational message only. No user action is required.

Does the Service Broker queue will cause this?

Error: 1222, State: 51. Lock request time out period exceeded. This is an informational message only. No user action is required.

$
0
0

Our production database upgrade from SQL Server 2008 R2 to SQL Server 2012 SP1 recently.

And the active tasks are still increasing, we have 690000 active tasks now.

find that many error message:

Date 8/18/2013 7:01:11 PM
Log SQL Server (Current - 8/18/2013 7:16:00 PM)
Source spid35s
Message
An error occurred in Service Broker internal activation while trying to scan the user queue 'Queue Name' for its status. Error: 1222, State: 51. Lock request time out period exceeded. This is an informational message only. No user action is required.

Does the Service Broker queue will cause this?

Error log loaded with stack dumps and error messages

$
0
0

Our error log is filled with errors of this nature:

Error: 9646, Severity: 16, State: 2.

An error occurred in the timer event cache. Error 845, state 1.
Process 491:0:2 (0x184c) Worker 0x00000010754D2160 appears to be non-yielding on Scheduler 24. Thread creation time: 13020506683971. Approx Thread CPU Used: kernel 1248 ms, user 13594083 ms. Process Utilization 10%. System Idle 89%. Interval: 20353254 ms.

A time-out occurred while waiting for buffer latch -- type 2, bp 00000010ADB0AB00, page 1:240, stat 0x9, database id: 16, allocation unit Id: 281474981494784/4784128, task 0x0000000751019498 : 0, waittime 300 seconds, flags 0x3038, owning task 0x0000000000000000. Not continuing to wait.

As well as these:

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

Is it all resource related?

Thank you,

Mike


Issues starting SSBExternal Activator (service-specific error code 21)

$
0
0

I installed SQL Server External Activator 2012 on my local machine. I have windows 7 Professional and SQL Server 2012 Express installed. After the installation I go to services to start it and receive the following error:

"Windows could not start the Service Broker External Activator on Local Computer. For more information, review the System Event Log. If this is a non-Microsoft service, contact the service vendor, and refer to service-specific error code 21."

I went to the servers system log this is the error I found:

"The Service broker External Activator service terminated with e service-specific error. The device is not ready..."

An idea what could be causing this? I get this error in these two environments:

Windows Server 2008 RS

SQL Server 2012 

AND

Windows 7 Professional

SQL Server 2012 Express

Service Broker, dialog lifetime and end conversation -

$
0
0

Hi,

Im looking for explanation of the scenario with dialog lifetime set. I have two sevices server and client - working in the same database on SQL 2008 Express. Client opens conversation with lifetime set and sends a message. On the server service side the message is received and replied - messages reach receivers. Then after some time the lifetime for conversation expires and both sides get error message. Both sides end conversation then.

And in sys.conversation_endpoints record for the service side of conversation remains with the state CLOSED. It is not purged from there (I know about 30 mins delay - but it sits there for hours, or days).The record for the client side disappears after client ends conversation.

I have read some posts and blogs on the service broker, the scenario is similar to most simple scenarios found there (including the one from the book on T-SQL programming for SQL 2005) except that conversation always ends with lifetime expiration.I think that this is not 'fire and forget' scenario (is it?).

Both sides execute this to end the conversation:

 

if @RecvReqMsgName = N'http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog'beginEND CONVERSATION @RecvReqDlgHandle;break;end;if @RecvReqMsgName = 'http://schemas.microsoft.com/SQL/ServiceBroker/Error'beginEND CONVERSATION @RecvReqDlgHandle;break;end;

 

Does anybody know why the server(target) conversation record remains forever?

There are also no messages left in client, server or transmision queue. Records have proper seecurity_timestamp value about 30 minutes ahead of the lifetime. What is interesting end_dialog_sequence is -1 in sys.conversation_endpoints.

Looks like server side has not received end dialog message or ack - is it becouse of lifetime error message ?

Is presence of error message prevent from receiving reply for end conversation - then why client side terminates properly (some race condition)?

Regards

 


far_principal_id in sys.conversation_endpoints table

$
0
0

Hi Everyone,

I have a bunch of conversations stuck in sys.transmission_queue and all of them have a far_principal_id=-1 in sys.conversation_endpoints. I don't get the significance of -1 in that column. What do I make of it? TIA


Mordechai Danielov

Unstoppable Database Mail

$
0
0

Hello,

I setup an alert system using Database Mail on SQL Server 2008 Std Windows 8

After a couple of successful tests, I started to receive the same email thousands of times. I could not stop it; stopped the queue, removed the account and profile, stop sql service. Eventually killing the Message Queuing processes seemed to help then enabling Service Broker started it again.

At this point, I am not sure what caused it, even where to start. Any idea?

The following is the code I use to send out emails.

while exists(select * from EmailsToGo WHERE alert = 0)     
begin       
SELECT TOP 1 @EmailID = EmailID,@Recipients = Recipients,             
@Subject = Subject, @Body = Body 
FROM EmailsToGo          
exec msdb.dbo.sp_send_dbmail @recipients = @Recipients, @subject = @Subject, @body = @Body         
UPDATE EmailsToGo SET alert = 1 where EmailID = @EmailID     
END

while exists(select * from EmailsToGo WHERE alert = 0)     begin         select top 1 @EmailID = EmailID,@Recipients = Recipients,             @Subject = Subject, @Body = Body from EmailsToGo          exec msdb.dbo.sp_send_dbmail @recipients = @Recipients, @subject = @Subject, @body = @Body         UPDATE EmailsToGo SET alert = 1 where EmailID = @EmailID     END
I feel like something messed up in msdb or Message Queuing service.


Event Notifications: insufficient system memory

$
0
0

I'm looking for a sanity check.  Service broker and Event Notifications are new to me, so it is possible I'm either abusing or incorrectly using the technology.  I'm experimenting with using Event Notifications and Server Broker to log error messages.  The process works pretty well as long as I don't do something stupid such as stressing the process by calling raiserror in a loop of a 100000 - twice.  It processed for a while, but eventual either SQL Server terminates (sev 25) or I had to force the SQL service to stop by killing it's process via task manager.  I could not connect to SQL Server or stop the service normally.  

 

I have several general questions.  I think they are good questions.  Any thoughts or suggestions would be appreciated. 

 

1) I'm looking into generating deadlock and blocking email alerts.  It appears that Event Notification is the way to go since there are very few events and I can respond to the event with an email.  Is there a better method to automate blocking and deadlock email alerts that include event details? 

 

2) If I wanted to retain some history of errors for the developers, should Event Notifications be avoided if a high number of errors can be generated by a badly formed T-SQL?  Avoid TRC_ERRORS_AND_WARNINGS and USER_ERROR_MESSAGE?  (I could tell the developers not to be stupid, but why would that stop them if it does not stop me?)

 

3) Is there a way to efficiently filter a Event Notification from entering the queue before the Receive statement is called?  I get some events that I throw away after receiving them.  For example, perhaps I want all events from all non-system databases without having to add a notification for each single non-system database.  Or I want all errors with severity 11-17 only? 

 

4) Is there a trick to filter out events from the procedure activated by the event.  I tried using raiserror to debug a procedure without thinking.  The result was that the queue never was empty because the processing produced more events to process.  As a result, I don't use raiserror and use a try-catch to avoid raising errors in the procedure activated. 

 

5) I can receive one message at a time using local variables or receive a batch of messages using a local table.  Is a small batch the best way even if there is memory pressure? 

 

6) In the activated procedure I continue processing in a loop until there are no more messages.  This seems to be the most efficient.  Is this always the case?  Should I exit the procedure after a set number (large) of messages have been received?  The procedure would activate again to continue processing? 

 

7) Is there any point to using the MAX_QUEUE_READERS setting when processing event notifications?  Should it be 1? 

 

8) I currently get the next conversation group id and process its messages within a transaction.  Is this a bad idea with event notifications?  Should I just call Receive and get the next batch?  I don't really care if I lose some messages if things are going badly.  Should I avoid wrapping the receive in a transaction? 

 

9) I could run a trace that starts with SQL Server; however, I think my only choice is to log to a file.  Is there a way to trace to a table using SQLTrace without running profiler?  I would like to automate the process and have the data in a table so that it can be easily queried and parsed for each database/team. 

 

10) Is there a way to fix my process and handle 100000 messages a minute?  Is there a way to skip messages when it gets to busy?  Can the query generating the messages get throttled - perhaps along with the query designer - before the server gets into trouble?  Query the memory used by a queue and drop/create the queue with a delay if there is an issue? 

 

I'm using a single CPU test machine with only 1 GB and 2 GB pagefile and a single disk.  OS: Windows 2003 R2 SP2.  SQL: 9.0.3054 and on 9.0.3228 (update package 6 just came out today).  I could add memory, but I think that would just permit me to queue more message before running into trouble. 

 

I'll add code shortly - length limit.

service broker manager has started

$
0
0

hi,

application verified that they are not using any service broker.

I am getting message/ or error log saying:

service broker manager has started and,

could not start service broker for database id: 10. A problem is preventing sql server from staring service broker. Check the sql server error log.

Question:

I am lose at what sort of error logs are they saying when i am already looking at the error logs from the LOG folder. How can i stop this error msg from popping up? 

Sql Mail service issue

$
0
0
Hello

My application and database are in different server, hence i created application folder as map drive in database server. But when i am trying to send mail using SQL mail service receiving below error.

request to suggest how to send attachments from map drive/ shared folders using SQL mail service.

Msg 22051, Level 16, State 1, Line 0
Attachment file \\192.168.0.55\UploadFiles\This Week Task List OLD_15Oct2013183539.xlsx is invalid.

Appreciate the support
Viewing all 461 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>