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

SqlDependency performance

$
0
0




Hi All,

I'm using SqlDependency (sql server 2008 r2) to get notification when data in some tables changes. The query notification is for cache invalidation.

There are three large tables and I want to get changes on a small subset of these tables. These three tables are changing frequently, but the subset is not changing frequently. I have a question about the performance impact.

How does the query notification track changes? Does it effect every query againsts these three tables ( not only for the subset)?

Performance is important in our system. If the sql dependency impacts db performance, we need to find another approach.

Thanks,

William





using triggers with service broker

$
0
0

Requirement: I am using triggers on a table to send the data from the table to a Queue using Service Broker.

CREATE MESSAGE TYPE SampleMessage AUTHORIZATION dbo VALIDATION = WELL_FORMED_XML

CREATE CONTRACT SampleContract AUTHORIZATION dbo (SampleMessage SENT BY INITIATOR);

CREATE SAMPLEQUEUE WITH STATUS = ON , RETENTION = OFF;

-- Create init Service CREATE SERVICE SampleServiceInitiator AUTHORIZATION dbo ON QUEUE dbo.SampleQueue (SampleContract);

-- Create target Service CREATE SERVICE [SampleServiceTarget] AUTHORIZATION dbo ON QUEUE dbo.SampleQueue (SampleContract);

THIS is part of trigger to actually initiate a dialog.

DECLARE @Handle UNIQUEIDENTIFIER; BEGIN DIALOG CONVERSATION @Handle FROM SERVICE [SampleServiceInitiator] TO SERVICE 'SampleServiceTarget' ON CONTRACT [SampleContract] WITH ENCRYPTION = OFF;

SEND ON CONVERSATION @Handle MESSAGE TYPE SampleMessageType;


I do not have a activation procedure on queue to end the conversation. If I have a stored procedure I can end the conversation as part of SP. It works perfect. where I put the code so that it means the receiver acknowledges the message and move the end point to closed status??? right now the conservation end points are stuck in conversing status.

Unable to start SQL Agent SQL Server 2008 R2

$
0
0

Unable to start SQL Agent SQL Server 2008 R2

Error logs

Date,Source,Severity,Message

10/30/2013 08:19:12,,Information,[098] SQLServerAgent terminated (normally)
10/30/2013 08:19:12,,Error,[298] SQLServer Error: 15247<c/> User does not have permission to perform this action. [SQLSTATE 42000] (DisableAgentXPs)
10/30/2013 08:19:11,,Error,[000] Error creating a new session
10/30/2013 08:19:11,,Error,[298] SQLServer Error: 229<c/> The INSERT permission was denied on the object 'syssessions'<c/> database 'msdb'<c/> schema 'dbo'. [SQLSTATE 42000]
10/30/2013 08:19:11,,Error,[298] SQLServer Error: 229<c/> The EXECUTE permission was denied on the object 'sp_sqlagent_get_startup_info'<c/> database 'msdb'<c/> schema 'dbo'. [SQLSTATE 42000]
10/30/2013 08:19:11,,Error,[298] SQLServer Error: 229<c/> The EXECUTE permission was denied on the object 'sp_sqlagent_has_server_access'<c/> database 'msdb'<c/> schema 'dbo'. [SQLSTATE 42000] (ConnIsLoginSysAdmin)

Service Broker to MSMQ?

$
0
0

Can Service Broker send messages to MSMQ?

Thanks,

Kuzey

One of the service broker spid causing our tempdb full. How to troubleshoot what exactly the issue with service broker?

$
0
0

One of the service broker spid causing our tempdb full. How to troubleshoot what exactly issue with service broker

Below is the broker_activated_tasks getting performed and No record found in transmission_queue tables

spid

database_id

queue_id

procedure_name

execute_as

47

8

87931635

[dbo].<spname>

1

database_id

queue_id

state

last_empty_rowset_time

last_activated_time

tasks_waiting

8

87931635

RECEIVES_OCCURRING

9/20/13 3:22 PM

9/25/13 5:28 AM

0


Rahul

Multiple inserts handling concurrency - Service Broker

$
0
0

Hi all,

I have a stored procedure that receives XML as input and it runs many checks (selects) in many tables, somewhere during the process it performs required selects with a few tables involved (never more than 10 tables but some of them might have many thousands of records), performs inserts or updates.

My matter is concurrency, I may deal with one insert but I may deal with 100 or 1000 at the same time.

Since SQL Server, by default applies READ Committed isolation level, deadlocks began to occur.

Some SQL enhancements and tunning were made. Using Execution Plan helped understanding some performance loss reading XML data, but deadlocks kept happening. Recently I analyzed SNAPSHOT isolation level and applied it successfuly (no more deadlocks since selects make no lock on destination tables). This works like a charm for something like 150 requests simultaneously.

My question here is how can I make this process quick but yet reliable, I mean, somehow If I deal with 100 requests I'm able to satisfy them in an acceptable manner, but I'm sure that if I deal with 1000 it will not go ok.

My question is if is possible to use Service Broker or some queue system that allows me something like I execute X requests at the same time, and after those requests are done I may execute X more (for example, 50 requests at the same time)?

An important note is that the same tables involved in this process are also involved in other processes that can be executed at the same time (or not) and are involved in an application that also can be using these tables.

Thank you for your opinions.

The connection was closed by the remote end, or an error occurred while receiving data: '64(The specified network name is no longer available.)'

$
0
0

Getting this error while configuring service broker on my network.

I have already checked below things.

1) Port 4022 is enabled on the firewall of both server.
2) Telnet to the port 4022 is working fine.
3) Able to connect cross database server throw SSMS.
4) GRANT CONNECT ON  ENDPOINT  and GRANT SEND ON  SERVICE already given.

Does anyone know why is this happening?

Once for all right permissions for SQLDependency PLEASE?

$
0
0
I took this description out of my search engine because it is exactly what is happening to us, so why bother writing it again.

The original post is unanswered here (http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic30682.aspx)

 but I hope that it will be solved here.

The blog entry posted by Sushil Chordia at
http://blogs.msdn.com/dataaccess/archive/2005/09/27/474447.aspx describes
the minimum requirements a Sql user should have for SqlDependency to work. I
have tried to apply them, but I still have some problems.

I am trying to create an Application Role in Sql Server 2005 RTM that
contains all the necessary rights for SqlDependency to work. I'm doing this
based on the information specified in the blog mentioned earlier.

Here's the script that creates a test-databases and the application-role:
CREATE DATABASE [TestDb] ON  PRIMARY
( NAME = N'TestDb', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\DATA\TestDb.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED,
FILEGROWTH = 1024KB )
LOG ON
( NAME = N'TestDb_log', FILENAME = N'C:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\DATA\TestDb_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB
, FILEGROWTH = 10%)
COLLATE Latin1_General_CI_AI
GO

USE TestDb
GO

CREATE TABLE [dbo].[tblPRODUCTS](ID INT NOT NULL, strNAME NVARCHAR(50) NOT
NULL)
GO

CREATE LOGIN [test] WITH PASSWORD=N'test', DEFAULT_DATABASE=[TestDb],
DEFAULT_LANGUAGE=[us_english], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO

CREATE USER [test] FOR LOGIN [test]
GO

EXEC sp_addrole 'sql_dependency_subscriber'
GO

CREATE ROLE [sqldependency_user]
GO

GRANT CREATE PROCEDURE to [sqldependency_user]
GRANT CREATE QUEUE to [sqldependency_user]
GRANT CREATE SERVICE to [sqldependency_user]
GRANT REFERENCES on
CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification ] to [sqldependency_user]
GRANT VIEW DEFINITION TO [sqldependency_user]
GRANT SELECT to [sqldependency_user]
GRANT SUBSCRIBE QUERY NOTIFICATIONS TO [sqldependency_user]
GRANT RECEIVE ON QueryNotificationErrorsQueue TO [sqldependency_user]
GRANT REFERENCES on
CONTRACT::[http://schemas.microsoft.com/SQL/Notifications/PostQueryNotification ] to [sqldependency_user]

EXEC sp_addrolemember 'sql_dependency_subscriber', 'test'
EXEC sp_addrolemember 'sqldependency_user', 'test'
GO

I have also written the following C# program that should work at this point
if I interpret that blog-entry correctly.
  class Program
  {
    private static string mConnectionString = "Data
Source=(local);Database=TestDb;Persist Security Info=false;Integrated
Security=false;User Id=test;Password=test";

    static void Main(string[] args)
    {
      using (SqlConnection oConnection = new SqlConnection(mConnectionString))
      {
        oConnection.Open();

        SqlDependency.Start(mConnectionString);

        ' there's some more code here...
      }
    }
  }


However, if I now run this program, I get the following exception on
SqlDependency.Start:
Unhandled Exception: System.Data.SqlClient.SqlException: The specified
schema name "dbo" either does
not exist or you do not have permission to use it.

I partially resolved this problem by doing the following:
GRANT CONTROL ON SCHEMA::[dbo] TO [adam_service_user]

However, when I run the application again, it now fails with the following
error on SqlDependency.Start:
Unhandled Exception: System.Data.SqlClient.SqlException: Cannot find the
user 'owner', because it do
es not exist or you do not have permission.
Cannot find the queue
'SqlQueryNotificationService-653e2c6f-51ff-488e-bca6-71be01a02206', because it
does not exist or you do not have permission.
Cannot find the service
'SqlQueryNotificationService-653e2c6f-51ff-488e-bca6-71be01a02206', because
it does not exist or you do not have permission.
Invalid object name
'SqlQueryNotificationService-653e2c6f-51ff-488e-bca6-71be01a02206'.

Apparently, there's still some additional permission required to use
SqlDependency that is not listed in Sushil's blog. I can bypass this problem
by making my role a member of the dbo-role, but I would like to know the
minimum role required to make this thing work.

Query notification firing for user other than user who registered it

$
0
0

Hi,

I posted this same question over at stack overflow and haven't received a response yet so I'm hoping to find some help here.

I've been using SqlDependency in a .NET 3.5 application for over 3 years without any problems. The scenario is as follows:

  1. Central windows service with a SqlDependency watching a table (let's call this Table A)
  2. Multiple users using a WPF application with a unique SqlDependency per user watching a table (Table A again)
  3. User queues a unit of work for processing in Table A
  4. SqlDependency fires on windows service
  5. Windows service processes all outstanding items in Table A and saves results to Table A
  6. Unique SqlDependency fires for each user who's results are available
  7. User processes their work

Recently, I've upgraded the system to .NET 4.5 and started seeing issues where changes would be put into the table we're monitoring, but the SqlDependency would never fire (both in the service and in the user application). I started digging into this further and noticed in my logs that at some point I would re-register the SqlDependency, but then the notification would never fire after that.

After seeing this behavior, I decided to run the profiler on SQL server to capture subscription events. From the data that was captured, I noticed that sometimes a subscription would be registered (with a unique ID) by one user but then it would be fired (with the same unique ID) by another user. This typically happens with the service I mentioned above and one or more of the users of the WPF application. (I've attached a screenshot of the the issue in the profiler results)

Is this expected behavior? That a notification can be fired for a different user than it was registered by? Does this point to a problem in the application layer? Any help is appreciated.


What happens when a queue is de-activated?

$
0
0
Hello:
ALTER QUEUE Qname WITH ACTIVATION (STATUS ='OFF');

If we use ALTER QUEUE to de-activated a queue, what happens to the currently executing instances of the activation SProc. For example, will the activation SProc immediately stop executing and roll the message back onto the queue or will the activation keep running until all the messages in the queue are processed?


TIA,
Dave

help understanding usage of Service Broker

$
0
0

Hello,

I am trying to learn/understand Service Broker and how it works and more importantly, what is the practical use of it?
Just like anything else, I googled on this and I kind of got very basic understanding on how to configure one(again, very basic) but what I could not comprehend in what Situations it is used??

Most of the videos/blogs, I referred say it is 'asynchoronizing messages systems that can send messages across sql sever databases ....' but what I do not understand like where is it required??
Does any body have good references that explain in what situations service broker is used?? Any help is appreciated.

In short, I would like learn about the practical usage of Service broker. Thank you


Hope it Helps!!

An error occurred in Service Broker internal activation while trying to scan the user queue

$
0
0

After Migrating our Production database from sql 2008 to Sql 2012 SPI, our service broker queues are showing errors in the event logs. Prior to the upgrade we were not seeing any errors. We can determine that the queues are working, but are wondering why we are seeing these errors all of a sudden? I have found other postings where people have seen the same problem after the upgrade.

Here is an example of the errors we are seeing.

 

An error occurred in Service Broker internal activation while trying to scan the user queue 'XX' for its status. Error: 1222, State: 51. Lock request time out period exceeded. This is an informational message only. No user action is required.

Broker Service in SQL Server 2012

$
0
0

Hi everyone,

I have seen this in System Center 2012 Update 1

"Issue 7
When a new SqlNotificationRequest instance is created, new rows are created in the sys.conversation_endpoints catalog view that has state="CO." Because the SqlNotificationRequest class does not provide any method to close the conversation accordingly, the sys.conversation_endpoints catalog view grows quickly to a very large number."

I have this problem in SQL Server 2012 Enterprise Edition , (in SQL Server 2008 R2 everything works).

My problem is that each time I create a new SqlDependency Object in my project there are multiple endpoints with is_system = 1 (view sys.conversation_endpoints) that are not closed. All endpoints that are not created from system do close and I can see them. I also set a timeout in the SqlDependency constructor so as to force the conversation to close after a period of time.

My question is : the reported error (Issue 7) has any relation with my problem? Is there any workaround till the next update?

(sys.conversation_endpoints has 10k new rows every day due to this error)

Thanks a lot.

Moving databases to another instance using Service Broker?

$
0
0

Hi,

We have a couple of production instances with many databases on SQL Server 2008 Std.

I want to implement an automated process to move inactive databases on multiple instances to a dedicated instance for inactive databases,  back and forth. A trigger on a status column on a user table will initiate the move out/in process. 

Do you think Service Broker can be used for this purpose?

Thanks,

Kuzey

Unable to acknowledge back messages received, with no symptoms

$
0
0

Hi, I hope someone can point me in the right direction here.

We have a production environment consisting of two separate instances, let's name them A and B, A being SQL 2005 and B SQL 2008 R2. The communication is mostly one way, A -> B.

Recently, the customer agreed to upgrade instance A with a SQL 2008 R2 on a brand new host, let's call it A'. In order to minimize impact on the platform, the idea is to keep A running and sending messages to B, restore a full backup of A on A', then halt the platform, restore an incremental backup on A' and restart the platform using A' as main database. A' would already be pointing to B for broker communication and routes would be changed on B to point to A' for the acknowledgments.

We have A' already in place and we are trying to assure broker communication. We are using transport security based on certificates, and already exchanged public keys between A' and B, replicating the same scenario in place for A and B. We have set up a test service on A' and B and tried to send a message from A' to B. And this is what we have:

  • The messages arrives at B, but the acknowledgment doesn't get back to A', so it retries the messages forever.
  • transmission_status column in sys.transmission_queue on A' is empty, so it confirms the point above.
  • In SQL Profiler on B we see the message arriving, the classifier decides the route as LOCAL. Also, we see the "Acknowledgement Sent" event.
  • In SQL Profiler on A' we only see the Message with Acknowledgment Sent event, nothing else. No droping messages, no errors whatsoever, nothing.
  • Using Get_Transmission_Status function on B to check the transmission status of the acknowledgment gives back an empty string.

I have double and triple checked the route from B to A' and it appears to be correct. Besides, I think I would have some kind of feedback through Get_Transmission_Status if that were the case.

Another thing we tried is to send a message from B to A'. We got nothing in transmission_status on B, and nothing received on A', including no event of any kind in a Profiler on A'.

What am I missing? Is there some way I can be sure the acknowledgments are arriving on A'?

Thanks





Using Service Broker to Notify Several C# Clinent(s) with one Message and Single Queue.

$
0
0

I would like to use Service Broker to notify several C# Clients with a change notification that they need to make a call to the database when something is updated by inserting a single message into a message queue and have all the clients receive it.  We are using SQL 2008 and it appears that all conversations between a client and SQL are one-to-one and cannot be many-to-one.  I have seen examples where each client must call into the database to setup the communication channel but that seems to be overkill for what I need.

Of course all clients should be able to read the message and then it would be removed from the queue after all registered clients have accessed the queue.  Thanks,

Thanks,

New Top Support Solutions blog

$
0
0

Hello

As part of our efforts to keep our communities informed about the most relevant content that address the top questions that we are getting in out forums and other support channels we want to introduce the new “Top Solution Content” blog (http://blogs.technet.com/b/topsupportsolutions).

In this blog you will find up-to-date and valuable information about Microsoft top support solutions for several of our popular products in the Server and Tools portfolio. You can use the tags (http://blogs.technet.com/b/topsupportsolutions/archive/tags) to easily locate the product of your preference or visit the home page to see what’s going on for the different Microsoft Enterprise and developer products. As a blog you can also subscribe to post and comments using the RSS feeds.

We hope this will reduce time and effort when you are looking for relevant content. Enjoy it!

Thanks

Microsoft Support team


Elvis Long
TechNet Community Support

Select from SSB.SendQ from another server by using linked server

$
0
0

Hi, I'm trying to run: select conversation_handle from [Linked_Server].SSB.sendQ

The error message I get is:  Invalid object name '[Linked_Server].SSB.sendQ'.

When I open the expand the linked server in my console, I only see 'Catalogs' and 'SSB'. But under SSB I only see 'Tables' and 'Views', and I do not see 'Service Broker' and the queues.

What I want to do, is it something that can be achieved by editing the properties of the linked server? Or it needs to be configured from the SSB itself, and how?

Thanks,

Dario

Conversations stuck in state of CONVERSING and not processing messages

$
0
0

Hey, all.  I'm having an issue where we have a number of table triggers which use service broker to document any DML statements run against those table.  The changes are inserted via service broker in to some tables we use for this auditing. When I trigger these events I can see the conversations with service broker started by querying sys.conversation_endpoints.  However, they stay in a state of CONVERSING and never seem to be processed by service broker until almost a day later.  I've tried disabling/re-enabling service broker on the database (yes, this is in Test), and also purging the conversations and trying again, but it seems there is a serious delay in getting service broker to process them.

Is there a way where I can force service broker to process these messages?  And what is an effective way to troubleshoot performance issues affecting service broker?

Any help is greatly appreciated!

SQL dependency

$
0
0

Sir

I am testing a Vb.net application to have SQL dependency with SQL server database. Infact I copied the sample code given in MSDN and only changed the database connection string.

I am getting the connection but the dependency_OnChange event gets fired repeatedly as in a loop.

The args e.Type is "Subscribe"

and e.info is Invalid.

I checked the SQL statement for the format but could not find any mistake.

Private Function GetConnectionString() As String Return "Server=OPS-TMIT\SQLEXPRESS;Database=FlightStatus;Integrated Security=true;" & _"User ID=;Password=;Trusted_Connection=True;Encrypt=False;" & _"Connection Timeout=30;Pooling=False;" End Function

Private Function GetSQL() As String Return "Select [FlightStatus].[dbo].[Data].[Auto], " & _"[FlightStatus].[dbo].[Data].[Arr Date] " & _"FROM [FlightStatus].[dbo].[Data] " & _"WHERE ([FlightStatus].[dbo].[Data].[Arr Date] = @Date1 );" End Function

Private Sub dependency_OnChange( _ ByVal sender As Object, ByVal e As SqlNotificationEventArgs) Dim someType = e.Type Dim someInfo = e.Info Dim someScource = e.Source ' This event will occur on a thread pool thread. ' It is illegal to update the UI from a worker thread ' The following code checks to see if it is safe ' update the UI. Dim i As ISynchronizeInvoke = CType(Me, ISynchronizeInvoke) ' If InvokeRequired returns True, the code ' is executing on a worker thread. If i.InvokeRequired Then ' Create a delegate to perform the thread switch Dim tempDelegate As New OnChangeEventHandler( _ AddressOf dependency_OnChange) Dim args() As Object = {sender, e} ' Marshal the data from the worker thread ' to the UI thread. i.BeginInvoke(tempDelegate, args) Return End If ' Remove the handler since it's only good ' for a single notification Dim dependency As SqlDependency = _ CType(sender, SqlDependency) RemoveHandler dependency.OnChange, _ AddressOf dependency_OnChange ' At this point, the code is executing on the ' UI thread, so it is safe to update the UI. changeCount += 1 ' Add information from the event arguments to the list box ' for debugging purposes only. ' Reload the dataset that's bound to the grid. GetData() End Sub Private Sub GetData()

' Empty the dataset so that there is only ' one batch worth of data displayed. dtSet.Clear() ' Make sure the command object does not already have ' a notification object associated with it. command.Notification = Nothing ' Create and bind the SqlDependency object ' to the command object. Dim dependency As New SqlDependency(command) AddHandler dependency.OnChange, AddressOf dependency_OnChange Using adapter As New SqlDataAdapter(command) adapter.Fill(dtSet, tableName) Me.DataGridView1.DataSource = dtSet Me.DataGridView1.DataMember = tableName End Using End Sub Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click Try ' Remove any existing dependency connection, then create a new one. SqlDependency.Stop(GetConnectionString()) SqlDependency.Start(GetConnectionString()) If connection Is Nothing Then connection = New SqlConnection(GetConnectionString()) End If If command Is Nothing Then ' GetSQL is a local procedure that returns ' a paramaterized SQL string. You might want ' to use a stored procedure in your application. command = New SqlCommand(GetSQL(), connection) Dim prm As New SqlParameter("@Date1", SqlDbType.DateTime2) prm.Direction = ParameterDirection.Input prm.DbType = DbType.DateTime2 prm.Value = "2013-11-18 00:00:00" command.Parameters.Add(prm) End If If dtSet Is Nothing Then dtSet = New DataSet() End If GetData() Catch ex As Exception MsgBox(ex.Message) End Try End Sub



Please advice where I have gone wrong !!


Manoj

Viewing all 461 articles
Browse latest View live


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