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

Are error messages created somewhere when an event_notifications are misconfigured?

$
0
0

Newbie question: We discovered that we had a value in sys.event_notifications.broker_instance that did not correspond to the value of sys.databases.service_broker_guid for any existing database. We were unaware of this for some time. Are there any error messages generated by Service Broker when this happens or is does it just not work?

Thanks,

Ron Rice


Ron Rice


Service Broker causes SqlExceptions

$
0
0
Hello,

I have used sql server service borker notification service and queue for my .Net application (windows service) to get query notification when any update in query(table).

in application i have used sqlDependency to get query notification on change.

this service and queue is working fine and i am getting query notitication in application.

In window service there are many (50 or more) sql operation perform in 1 seconds. if i am using sql server service broker,
i was getting SQLException like :

System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is open.
System.InvalidOperationException: ExecuteReader requires an open and available Connection. The connection's current state is closed.

if i disable borker and delete service/queue, then everything working fine (no sql exception)

Question : does Service borker caues sql server performance issue with connection from C# ?

if you need sample then will provide sample how i have implemented service borker in .Net application.

it would be great if you provide any solution for this.


Thanks in Advance.

SqlDependency OnChange Event Fires repeatedly

$
0
0

I am using the SqlDependency to notify me of data changes in a table. However, as soon as I start it, the OnChange event fires over and over even though no data has changed.

 

Essentially All I want to do is be notified when records are inserted into a table. I am able to get another example to work using a Service Broker Queue and a sql query of WAITFOR ( RECEIVE CONVERT(int, message_body) AS msg FROM QueueMailReceiveQueue ) However I would prefer not to use a queue for once my messages have been read they are taken off the queue and I would rather control that manually.

 

Any help with getting SqlDependency to notify my app when records are added and not over and over when the data has changed would be great.

 

Here is my code:

 

Code Snippet

public

partialclassForm1 : Form {

 

publicstaticeventOnChangeEventHandler OnChange;

string _strConnString = "Data Source=localhost;Integrated Security=SSPI;Initial Catalog=email_queue;Pooling=False;";

string _strSql = "SELECT email_id from email where isprocessed = 0";

privateDataSet dataToWatch = null;

privateSqlConnection connection = null;

privateSqlCommand command = null;

SqlDependency dependency = null;

SqlDataReader sdr = null;

 

public Form1() {

InitializeComponent();

}

 

privatevoid button1_Click(object sender, EventArgs e) {

SqlDependency.Stop(_strConnString);

SqlDependency.Start(_strConnString);

if (connection == null) {

connection = newSqlConnection(_strConnString);

connection.Open();

}

if (command == null) {

command = newSqlCommand(_strSql, connection);

}

if (dataToWatch == null) {

dataToWatch = newDataSet();

}

GetData();

}

 

privatevoid GetData() {

dataToWatch.Clear();

command.Notification = null;

dependency = newSqlDependency(command);

dependency.OnChange += newOnChangeEventHandler(dependency_OnChange);

command.CommandTimeout = 400;

using (SqlDataAdapter adapter = newSqlDataAdapter(command)) {

adapter.Fill(dataToWatch, "email");

}

}

 

privatevoid dependency_OnChange(object sender, SqlNotificationEventArgs e) {

ISynchronizeInvoke i = (ISynchronizeInvoke)this;

if (i.InvokeRequired) {

OnChangeEventHandler tempDelegate = newOnChangeEventHandler(dependency_OnChange);

object[] args = { sender, e };

i.BeginInvoke(tempDelegate, args);

return;

}

dependency = (SqlDependency)sender;

dependency.OnChange -= dependency_OnChange;

this.Text = DateTime.Now.ToString();

GetData();

}

 

privatevoid Form1_FormClosed(object sender, FormClosedEventArgs e) {

SqlDependency.Stop(_strConnString);

if (connection != null) {

connection.Close();

}

}

}

 

 

Message only arrives on queue once.

$
0
0

Hi,

I am new to SQL Service Broker and am currently trying to develop a POC.
I need to call a web service when a insert is made on a table. I have setup 3 queues and 3 services with associated message types (code below).

I have had some success after running the code below and performing an insert I see the messages appear on the following queues:

TargetPostQueue
InitiatorPostQueue
NotificationPostQueue

Then I start the Service Broker External Activator and the message is taken off NotificationPostQueue as expected and passed to my dummy console app that just prints out the args passed; for now.

The problem is after this no other messages appear on the NotificationPostQueue no matter how many inserts I do.
I see them appear on the TargetPost and InitiatorPost queues but nothing moves to the NotificationPostQueue. I'm sure this has something to do with me not ending the conversation but am unsure. What I can do when this happens, for now, is drop and delete the database then recreate it to give me one more go but it's taking too long.

Code for creating queue's and services

-- Create message types
CREATE MESSAGE TYPE [//MetLife/BPA/RequestPostMessage]  VALIDATION = WELL_FORMED_XML;
CREATE MESSAGE TYPE [//MetLife/BPA/ReplyPostMessage]    VALIDATION = WELL_FORMED_XML;
GO

-- Create contract
CREATE CONTRACT [//MetLife/BPA/PostContract]
     ([//MetLife/BPA/RequestPostMessage] SENT BY INITIATOR,
     [//MetLife/BPA/ReplyPostMessage] SENT BY TARGET
);
GO

-- Create target queue and service
CREATE QUEUE TargetPostQueue WITH RETENTION = ON;
CREATE SERVICE [//MetLife/BPA/TargetPostService]
     ON QUEUE TargetPostQueue([//MetLife/BPA/PostContract]);
GO

-- Create the initiator queue and service
CREATE QUEUE InitiatorPostQueue WITH RETENTION = ON;
CREATE SERVICE [//MetLife/BPA/InitiatorPostService]
     ON QUEUE InitiatorPostQueue([//MetLife/BPA/PostContract]);
GO

-- Create a notification for External Activator
CREATE QUEUE NotificationPostQueue
CREATE SERVICE [//MetLife/BPA/NotificationPostService]
    ON QUEUE NotificationPostQueue([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification])
CREATE EVENT NOTIFICATION EventQueueActivation
    ON QUEUE [TargetPostQueue]
    FOR QUEUE_ACTIVATION
    TO SERVICE '//MetLife/BPA/NotificationPostService', 'current database';
GO

Code for Trigger and Test Table

CREATE TABLE [Policies]
(
    PolicyId INT NOT NULL IDENTITY(1,1),
    Amount MONEY NOT NULL,
    BrokerName NVARCHAR(50) NOT NULL
)
GO
-- Trigger will add a message into a ImportQueue
CREATE TRIGGER OnPolicyInserted ON [Policies] FOR INSERT
AS
BEGIN 
    BEGIN TRANSACTION;
        DECLARE @ch UNIQUEIDENTIFIER
%2

SQL Server 2008 R2 service broker implementation

$
0
0

Hi, We are using a SQL Server 2008 R2 database to support an e-commerce application which is written in C#. I am pretty new to the concept of service broker.

Could you please help me understand what service broker is?

I am trying to understand how would implementing service broker help?

What benefits do I get if I were to implement it?

Is service broker supported in future SQL Server releases?

Thanks in advance..........


Ione

"Broker / DBM Transport:Receive I/O Bytes Total" counter is missing.

$
0
0

Hi

I noticed that "Receive I/O Bytes Total" and "Send I/O Bytes Total" counters are missing under "Broker / DBM Transport" object.


However, documentation says it should be there, http://msdn.microsoft.com/en-us/library/ms191226.aspx

My SQL server version is 2014 CU3. 


Любовь долготерпит, ...

Clearing all messages from a service broker queue

$
0
0

Hi All,

Iam currently trying to remove the messages from the queue if the count is more than 15000 as shown below in the stored procedure :

      Declare @CountMBSClientStatusSendQueue BIGINT
      SELECT  @CountMBSClientStatusSendQueue=rows
      From sys.partitions P
      Inner Join sys.internal_tables IT On IT.object_id = P.object_id
      Where IT.parent_object_id = object_id('MBSClientStatusSendQueue')
      And P.index_id In (1, 0)

      IF @CountMBSClientStatusSendQueue > 15000 
            ALTER DATABASE MBS SET NEW_BROKER WITH ROLLBACK IMMEDIATE

But the memory usage of the Sql server was very high and effecting the performance of the sql server. So I would like to know the easiest and the best way to cleanup the messages in the queues after the count is more than 10000

Kindly help me on the same.

Thanks,

Ram


ram

Log shipping failed when cluster failed over to second node

$
0
0

i have a clustered environment with node 1 and node 2

node one is active node and up 99 % of the time so while it was on node one i setup log shipping for this server.

while configuring the log shipping i chosed a local drive to store log backups and also gave the shared path of same drive in the configuration option.

when clustered failed over to second node log shipping started failing, even thogh there was shared paht of the same folder and should have been accessable to node 2 for backing up log for log shipping,

Please advise the solution.

Regards

 

k


Issue with SQLDependency along with Enity Framework and C#

$
0
0

Hi All,

I am trying to run a sample created using C# for SQL dependency. Whenever certain data is inserted in given table, I want a notification in my C# application. Right now, I am having both (my C# application as well as my SWl Server 2008 R2) the setups on the same machine which is not connected to any network.

My problem is, although my broker service is enabled  SQL server is not throwing me notification back in my C# application, although I modified data in my database. In simpler words, my sqlDependency_Onchange event is not firing.

Please help me out.


Regards, http://www.shwetalodha.blogspot.in/


Unable to enable service broker

$
0
0

Dear all,

I tried to create DBMail in one of our prod server, i did the following operation at start getting error. Kindly help me how to avoid this problem

alter database msdb set enable_broker with no_wait

Error: Database state can't be changed while other users are using the database 'msdb'

Alter database statement failed

Note: I just verified may be anyone using the database but i'm the only user working on that.


DBA

Best practice for cleaning up conversations after a recieve timeout

$
0
0

We have a pattern where sql server sends a message through service broker and waits for a response (say 10 ten secs), if it doesn't get a response, it will assume a default response and carry on. The response may come later and also end the conversation target side. However there is no-one to receive the response (which is no longer needed). We have clean up script on a sql agent job but we were wondering if there is a cleaner way to handle these situations


When to use WAITFOR?

$
0
0

Hi all,

I'm in doubt whether to use WAITFOR RECEIVE in my activation SP or not.

Actually I'm confused if WAITFOR is necessary in case I have activation SP or just RECEIVE is enough inside it.

Any help would be greatly appreciated.

Leila


Determine if Notifications Firing

$
0
0
I am now to Service Broker and SQL Notifications and am working on an application that needs SQL Notification. I am having problems with the application working intermittently depending on the environment (Windows 7, 8, or Server 2012). In troubleshooting, I am trying to determine if the notifications are firing correctly to eliminate one issue, but I am not sure how to do this. I have verified Service Broker for the database is enabled, but am not sure how to monitor if notifications are sent when the database changes. Any help would be appreciated.

Service Broker Messages

$
0
0

Hi,

I've the below messages appearing in the sql error logs plenty of times. No idea what's the problem. Any insight ?

spid25s	The query notification dialog on conversation handle '{8BCD7D78-1340-E411-A2AF-0050569D1B40}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8490</Code><Description>Cannot find the remote service &apos;SqlQueryNotificationService-34610a75-1b8a-427b-9d14-076b22dff07e&apos; because it does not exist.</Description></Error>'.
spid59	Error: 28054, Severity: 11, State: 1.
spid59	Service Broker needs to access the master key in the database 'MyData'. Error code:26. The master key has to exist and the service master key encryption is required.
TIA !

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.

Where is the query notification coming from?

$
0
0

When I execute a stored procedure and look at the execution plan, I see some "clustered index scans" where I'm not expecting them ... and they appear to be coming from "query_notification" objects.

Is there anyway in SQL Server to see what the source of the query notification is, and to actually stop or clear that notification?

Need help to figure out this SqlQueryNotificationService error.

$
0
0

I found every several minutes, sometimes one or twice in an hour, I still get a dozen error like below logged in SQL Log.  See the error is "You do not have permission to access the service". I found some articles on other errors, but nothing about this error.  I want to get more information on this, and a way to trace what is the permission about and which user doesn't have the permission.


Source  spid26s

Message
The query notification dialog on conversation handle '{E6FC299F-8BFE-DC11-A4E1-000D5670268E}.' closed due to the following error: '<?xml version="1.0"?><Error xmlns="http://schemas.microsoft.com/SQL/ServiceBroker/Error"><Code>-8494</Code><Description>You do not have permission to access the service &apos;SqlQueryNotificationService-9ff8b39d-90a8-45bc-83a7-23837920774d&apos;.</Description></Error>'.

 

 

thanks

service broker queue size

$
0
0

Hi All,

One of my client/customer is asking us to set up SERVICE BROKER QUEUE SIZE job, is the customer really intend about creating job for  SERVICE BROKER QUEUE SIZE, if so how to create job for this?

Unable to reach Target Service issues after receiving message

$
0
0

Hello everyone,

I am working on a demo for my devs/dba at work regarding the use of service broker, why we should start using it, and other fun facts that just go above initial implementation.  Part of this demo includes the routing capabilities for cross instance conversations. 

The good news is that I get messages to from Instance A to Instance B.  The issue I am having is after receiving the message on Instance B, I send a response back, and that is failing.  For the life of me, I cannot figure out why.  The error I am receiving is:

"The target service name could not be found. Ensure that the service name is specified correctly and/or the routing information has been supplied."

In doing research on Google/Bing/Yahoo/Various Forums, the consensus seems to be that this is usually an issue with either A) Remote Service Binding or B) Case Sensitivity when specifying the server.  Maybe I have been looking at this code to long, but I cannot find an issue with either of these as I currently understand them.  So, I am looking for help.

Here are the full scripts that I am running.  Please note that these scripts are not configured to run all the way through, but in blocks.  I apologize for this in advance.

ServerA Script:
https://onedrive.live.com/redir?resid=ED3BB9E286990092!250&authkey=!AHr6nNdQgxnCYiQ&ithint=file%2ctxt

ServerB Script:
https://onedrive.live.com/redir?resid=ED3BB9E286990092!249&authkey=!AB_TXg0S2Rgwa38&ithint=file%2ctxt

I am using a VM, where I have installed 2 instance of SQL Server 2012 Developer Ed, SP2, CU1.  Instance1 is call ServerA.  Instace2 is called Server2. 

Thank you very much for any assistance you are able to provide. 

Sincerely,

Nathan Heaivilin


Failed to verify Authenticode signature on DLL msxmlsql.dll

$
0
0

Hello, I got this error message. The server is experiencing issue of service broker suddenly stopping, so we are ruling out all errors at this point. Server is setup with HADR.

Win Server 2008 R2 Ent SP1

SQL 2012 11.0.3349 Ent

Log Name:      Application
Source:        MSSQL$SQL01
Date:          4/18/2013 7:17:26 AM
Event ID:      33081
Task Category: Server
Level:         Information
Keywords:      Classic
User:          N/A
Computer:      SQL01.xxxxxx.xxx
Description:
Failed to verify Authenticode signature on DLL 'C:\Program Files\Microsoft SQL Server\MSSQL11.SQL01\MSSQL\Binn\msxmlsql.dll'.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name="MSSQL$SQL01" />
    <EventID Qualifiers="16384">33081</EventID>
    <Level>4</Level>
    <Task>2</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2013-04-18T11:17:26.000000000Z" />
    <EventRecordID>28935</EventRecordID>
    <Channel>Application</Channel>
    <Computer>SQL01.xxxxxx.xxx</Computer>
    <Security />
  </System>
  <EventData>
    <Data>C:\Program Files\Microsoft SQL Server\MSSQL11.SQL01\MSSQL\Binn\msxmlsql.dll</Data>
    <Binary>398100000A0000000F000000500052004F004400530051004C0031005C0043004F00530051004C000000040000004F006E0065000000</Binary>
  </EventData>
</Event>

Thanks.

Viewing all 461 articles
Browse latest View live


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