Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Scheduled Rule Error Redux (Attn Diane)

 
   Database Help (Home) -> Notification Services RSS
Next:  Sending Messages to attached users  
Author Message
Utf-8BTko

External


Since: Feb 26, 2004
Posts: 10



(Msg. 1) Posted: Wed Mar 24, 2004 2:21 pm
Post subject: Scheduled Rule Error Redux (Attn Diane)
Archived from groups: microsoft>public>sqlserver>notificationsvcs (more info?)

In a previous thread you mentioned that the Event view is automatically created and deleted when necessary. When exactly is this created and deleted? In particular, I'm wondering if when a scheduled event rule is fired, is this view available? It appears to me through all my tests, that it is not. I always get the "Invalid object name" error when I try to reference this view in my scheduled event actions.

 >> Stay informed about: Scheduled Rule Error Redux (Attn Diane) 
Back to top
Login to vote
Diane Larsen MSFT

External


Since: Sep 02, 2003
Posts: 36



(Msg. 2) Posted: Thu Mar 25, 2004 1:47 pm
Post subject: Re: Scheduled Rule Error Redux (Attn Diane) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Yes, I believe this is the case. I tested this on an event-driven app just
to verify my previous answer. If you start an instance, submit events, and
then refresh the Views node in Enterprise manager, you should see the event
view appear. You have to time it right (or be lucky) because the view will
disappear.

If you have verified that your query works in query analyzer (you do need to
change the query in QA to get rid of rid of the notify function and use the
table names), and your application still is not working, I'll ask someone
else to take a look at your other thread. Like I said previously, it's often
difficult for me to troubleshoot query errors by just looking at the code,
but maybe someone in the group can spot something I can't.

-Diane

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
<a style='text-decoration: underline;' href="http://www.microsoft.com/info/cpyright.htm." target="_blank">http://www.microsoft.com/info/cpyright.htm.</a>


"NJ" <anonymous.DeleteThis@discussions.microsoft.com> wrote in message
news:28016C5F-B694-46D0-A102-91873BE455EA@microsoft.com...
 > In a previous thread you mentioned that the Event view is automatically
created and deleted when necessary. When exactly is this created and
deleted? In particular, I'm wondering if when a scheduled event rule is
fired, is this view available? It appears to me through all my tests, that
it is not. I always get the "Invalid object name" error when I try to
reference this view in my scheduled event actions.<!-- ~MESSAGE_AFTER~ -->

 >> Stay informed about: Scheduled Rule Error Redux (Attn Diane) 
Back to top
Login to vote
Utf-8BTko

External


Since: Feb 26, 2004
Posts: 10



(Msg. 3) Posted: Fri Mar 26, 2004 4:01 pm
Post subject: Re: Scheduled Rule Error Redux (Attn Diane) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Ok, I figured this whole issue out I think. The documentation isn't too clear on this, so it took trial and error to figure out. It appears to me that:

1. You cannot refer to the Event view in a <ScheduledRule/Action> node. The view is not available at the time a scheduled rule is fired. You must instead store all event information in a Chron table (using the ChronicleRule node) and reference the Chron table in this node.

2. Along the same lines, you cannot refer to a Subscription view in <ChronicleRule/Action> node. This is because this view references the CurrentSubscriptions table and this table may (more likely than not) not be populated at the particular time the rule is being fired.

In my case though, I have subscribers subscribed at different times and I want them to receive only for events they have not received yet. So, I had to fix the Chron table up a little bit by adding a sent flag and a subscriberID along with the other fields used by the notification class. I populate the Chron table with all the new events cross joined with all subscribers subscribed to this event class (I have to reference the subscription table for this, not the view). Then in the ScheduledRule node, after notifications have been generated, I update the sent flag. This allows me to track which events have been sent to whom and block people from getting duplicates.

Here's an example - the GUID I use here can be any unique value that you can compare against. This goes in the EventClass node:

<ChronicleRule><RuleName>MyEventsChronRule</RuleName><Action>
  INSERT INTO MyEventsChron(GUID, SubscriberID)
  SELECT e.GUID, s.SubscriberID
  FROM MyEvents e
  CROSS JOIN NSMySubscriptionsSubscriptions s
  WHERE e.GUID NOT IN (SELECT GUID FROM MyEventsChron)
  </Action></ChronicleRule><Chronicles><Chronicle><ChronicleName>MyEventsChron</ChronicleName><SqlSchema><SqlStatement>
   IF EXISTS(SELECT name FROM dbo.sysobjects WHERE name = 'MyEventsChron') DROP TABLE dbo.MyEventsChron
   CREATE TABLE MyEventsChron(
   [GUID] nvarchar(50),
   [SubscriberID] nvarchar(255),
   [Sent] bit DEFAULT(0)
   )
   </SqlStatement></SqlSchema></Chronicle></Chronicles>

This goes in the SubscriptionClass node:

<ScheduledRules><ScheduledRule><RuleName>MySubscriptionsRule</RuleName><Action>
    SELECT dbo.MyNotificationNotify(s.SubscriberId,
    s.DeviceName,
    s.SubscriberLocale,
    e.GUID
)
    FROM MyEventsChron e
    CROSS JOIN MySubscriptions s
    WHERE e.Sent = 0 and e.SubscriberID = s.SubscriberID

    UPDATE MyEventsChron
    SET Sent = 1
    WHERE SubscriberID IN (SELECT SubscriberID
    FROM MySubscriptions)
    </Action></ScheduledRule></ScheduledRules>

Hope this helps somebody... I sure had a hard time figuring it out...<!-- ~MESSAGE_AFTER~ -->
 >> Stay informed about: Scheduled Rule Error Redux (Attn Diane) 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> Notification Services All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]