Showing posts with label broker. Show all posts
Showing posts with label broker. Show all posts

Saturday, February 25, 2012

Query Notifications/ Service Broker problem

Hey , I encountered a problem using SqlDependency and notification services.

I’ve created a database with tools from c# Express 2005 and attached it to the sql server express 2005. And it turned out that ‘dependency_OnChange’ in my application is triggered each time I execute the command.ExecuteReader(); and it shouldn’t, because the command is just the select statement of columns and rows for which I wait to be modified.

SqlDependency dependency = new SqlDependency(command);

dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

command.ExecuteReader();//when the program gets here dependency_OnChange is called

So I Used the example from here :

http://msdn2.microsoft.com/en-us/library/a52dhwx7.aspx

and with AdventureWorks it behaves as it should , but when I change the connection string and select statement in the example to work with MyDatabase, the problem appears again.

So there is something wrong with MyDatabase ?

The select statement I used was “select Name, Pass from Users where Name like ‘L%’”;

So theoretically this should work but it does not and I end up in an infinite loop with

dependency_OnChange called cyclically …

I’d be grateful for any advice !

What are the dependency_OnChange paramater values passed in when the callback is notified?

I suspect the SqlNotificationEventArgs argument has a value of 'Subscribe' for the notification type, indicating an error in setting up the notification. If the statement you included is the exact statement you'd tried, then the problem is that your query is not respecting the Query Notifications restrictions. The query select Name, Pass from Users where Name like ‘L%’ is not properly schema bound, the Users table name should be bound with a schema name (e.g. dbo.Users).

HTH,
~ Remus

Query notifications and replication

Anyone using query notifications with replication? We have a replicated db
(transactional one way) and I have to turn service broker on for an app that
will use query notifications and I was wondering what effect that will have
on replication.
Thanks in advance.
According to my understanding of NS, apart from the resultant use of system
resources, there isn't really any overlap. There could be an impact if
Notification Services is polling the same tables on the subscriber that are
being replicated to - the usual blocking that would occur with any such
queries.
Paul Ibison

Query notifications (service broker) and mirroring

Hi,
I'm trying to turn on service broker so we can use query notifications in a
mirrored database. However I get the following when I try to run ALTER
DATABASE <db>
SET ENABLE_BROKER:
Msg 9778, Level 16, State 1, Line 2
Cannot create a new Service Broker in a mirrored database "testDB".
Msg 5069, Level 16, State 1, Line 2
ALTER DATABASE statement failed.
Can you use query notifications with a mirrored db?
Thanks in advance.
You must enable broker before the mirroring session is enabled. You should
first check if the broker is enabled in the first place
(sys.databases.is_broker_enabled). If is not, then you must stop the
mirroring session, enable the broker and re-establsih the mirroring session
from scratch.
HTH,
~ Remus
"sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
news:30FC2CF3-B85C-4B40-A4FD-D028F19CD6D8@.microsoft.com...
> Hi,
> I'm trying to turn on service broker so we can use query notifications in
> a
> mirrored database. However I get the following when I try to run ALTER
> DATABASE <db>
> SET ENABLE_BROKER:
> Msg 9778, Level 16, State 1, Line 2
> Cannot create a new Service Broker in a mirrored database "testDB".
> Msg 5069, Level 16, State 1, Line 2
> ALTER DATABASE statement failed.
>
> Can you use query notifications with a mirrored db?
> Thanks in advance.
|||Remus ,
Thanks for your reply. Will the service broker failover along with the
database?
"Remus Rusanu [MSFT]" wrote:

> You must enable broker before the mirroring session is enabled. You should
> first check if the broker is enabled in the first place
> (sys.databases.is_broker_enabled). If is not, then you must stop the
> mirroring session, enable the broker and re-establsih the mirroring session
> from scratch.
> HTH,
> ~ Remus
> "sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
> news:30FC2CF3-B85C-4B40-A4FD-D028F19CD6D8@.microsoft.com...
>
>
|||Yes
"sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
news:4B43EA5F-3340-41DD-9407-A0ED711F2726@.microsoft.com...[vbcol=seagreen]
> Remus ,
> Thanks for your reply. Will the service broker failover along with the
> database?
>
> "Remus Rusanu [MSFT]" wrote:

Query notifications (service broker) and mirroring

Hi,
I'm trying to turn on service broker so we can use query notifications in a
mirrored database. However I get the following when I try to run ALTER
DATABASE <db>
SET ENABLE_BROKER:
Msg 9778, Level 16, State 1, Line 2
Cannot create a new Service Broker in a mirrored database "testDB".
Msg 5069, Level 16, State 1, Line 2
ALTER DATABASE statement failed.
Can you use query notifications with a mirrored db?
Thanks in advance.You must enable broker before the mirroring session is enabled. You should
first check if the broker is enabled in the first place
(sys.databases.is_broker_enabled). If is not, then you must stop the
mirroring session, enable the broker and re-establsih the mirroring session
from scratch.
HTH,
~ Remus
"sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
news:30FC2CF3-B85C-4B40-A4FD-D028F19CD6D8@.microsoft.com...
> Hi,
> I'm trying to turn on service broker so we can use query notifications in
> a
> mirrored database. However I get the following when I try to run ALTER
> DATABASE <db>
> SET ENABLE_BROKER:
> Msg 9778, Level 16, State 1, Line 2
> Cannot create a new Service Broker in a mirrored database "testDB".
> Msg 5069, Level 16, State 1, Line 2
> ALTER DATABASE statement failed.
>
> Can you use query notifications with a mirrored db?
> Thanks in advance.|||Remus ,
Thanks for your reply. Will the service broker failover along with the
database?
"Remus Rusanu [MSFT]" wrote:

> You must enable broker before the mirroring session is enabled. You should
> first check if the broker is enabled in the first place
> (sys.databases.is_broker_enabled). If is not, then you must stop the
> mirroring session, enable the broker and re-establsih the mirroring sessio
n
> from scratch.
> HTH,
> ~ Remus
> "sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
> news:30FC2CF3-B85C-4B40-A4FD-D028F19CD6D8@.microsoft.com...
>
>|||Yes
"sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
news:4B43EA5F-3340-41DD-9407-A0ED711F2726@.microsoft.com...[vbcol=seagreen]
> Remus ,
> Thanks for your reply. Will the service broker failover along with the
> database?
>
> "Remus Rusanu [MSFT]" wrote:
>

Query notifications (service broker) and mirroring

Hi,
I'm trying to turn on service broker so we can use query notifications in a
mirrored database. However I get the following when I try to run ALTER
DATABASE <db>
SET ENABLE_BROKER:
Msg 9778, Level 16, State 1, Line 2
Cannot create a new Service Broker in a mirrored database "testDB".
Msg 5069, Level 16, State 1, Line 2
ALTER DATABASE statement failed.
Can you use query notifications with a mirrored db?
Thanks in advance.You must enable broker before the mirroring session is enabled. You should
first check if the broker is enabled in the first place
(sys.databases.is_broker_enabled). If is not, then you must stop the
mirroring session, enable the broker and re-establsih the mirroring session
from scratch.
HTH,
~ Remus
"sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
news:30FC2CF3-B85C-4B40-A4FD-D028F19CD6D8@.microsoft.com...
> Hi,
> I'm trying to turn on service broker so we can use query notifications in
> a
> mirrored database. However I get the following when I try to run ALTER
> DATABASE <db>
> SET ENABLE_BROKER:
> Msg 9778, Level 16, State 1, Line 2
> Cannot create a new Service Broker in a mirrored database "testDB".
> Msg 5069, Level 16, State 1, Line 2
> ALTER DATABASE statement failed.
>
> Can you use query notifications with a mirrored db?
> Thanks in advance.|||Remus ,
Thanks for your reply. Will the service broker failover along with the
database?
"Remus Rusanu [MSFT]" wrote:
> You must enable broker before the mirroring session is enabled. You should
> first check if the broker is enabled in the first place
> (sys.databases.is_broker_enabled). If is not, then you must stop the
> mirroring session, enable the broker and re-establsih the mirroring session
> from scratch.
> HTH,
> ~ Remus
> "sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
> news:30FC2CF3-B85C-4B40-A4FD-D028F19CD6D8@.microsoft.com...
> > Hi,
> > I'm trying to turn on service broker so we can use query notifications in
> > a
> > mirrored database. However I get the following when I try to run ALTER
> > DATABASE <db>
> > SET ENABLE_BROKER:
> >
> > Msg 9778, Level 16, State 1, Line 2
> > Cannot create a new Service Broker in a mirrored database "testDB".
> > Msg 5069, Level 16, State 1, Line 2
> > ALTER DATABASE statement failed.
> >
> >
> > Can you use query notifications with a mirrored db?
> >
> > Thanks in advance.
>
>|||Yes
"sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
news:4B43EA5F-3340-41DD-9407-A0ED711F2726@.microsoft.com...
> Remus ,
> Thanks for your reply. Will the service broker failover along with the
> database?
>
> "Remus Rusanu [MSFT]" wrote:
>> You must enable broker before the mirroring session is enabled. You
>> should
>> first check if the broker is enabled in the first place
>> (sys.databases.is_broker_enabled). If is not, then you must stop the
>> mirroring session, enable the broker and re-establsih the mirroring
>> session
>> from scratch.
>> HTH,
>> ~ Remus
>> "sqlboy2000" <sqlboy2000@.discussions.microsoft.com> wrote in message
>> news:30FC2CF3-B85C-4B40-A4FD-D028F19CD6D8@.microsoft.com...
>> > Hi,
>> > I'm trying to turn on service broker so we can use query notifications
>> > in
>> > a
>> > mirrored database. However I get the following when I try to run ALTER
>> > DATABASE <db>
>> > SET ENABLE_BROKER:
>> >
>> > Msg 9778, Level 16, State 1, Line 2
>> > Cannot create a new Service Broker in a mirrored database "testDB".
>> > Msg 5069, Level 16, State 1, Line 2
>> > ALTER DATABASE statement failed.
>> >
>> >
>> > Can you use query notifications with a mirrored db?
>> >
>> > Thanks in advance.
>>