microsoft.public.sqlserver.notificationsvcs
[Top] [All Lists]

Re: How to verify if subscriber exists?

Subject: Re: How to verify if subscriber exists?
From: Joe Webb
Date: Sat, 09 Dec 2006 09:12:50 -0600
Newsgroups: microsoft.public.sqlserver.notificationsvcs
Throwing exceptions is a *very* resource intensive operation and
should not be part of the normal design of an application. It should
only be used for truly unexpected events.

However, having said that, I do not know of a way to check to see if a
subscriber exists without using a try catch block.  

One thing that I do to try to minimize that, though, is to have a
non-SSNS table that has subscriberIds and their passwords (remember
that SSNS doesn't have the concept of subscriber passwords). So before
I do anything that might cause a subscriber exception, I check it
through the password table. 

HTH...

Joe


-- 
Joe Webb
SQL Server MVP
http://www.sqlns.com


~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811 

I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)




On Fri, 8 Dec 2006 23:51:40 -0000, "TonyS" <[email protected]> wrote:

>What's does 'right way' mean?
>'Right way' is subjective and changes with time.
>
>Similarly 'Bad practice', in the absence of something else found within a 
>reasonable time searching, is meaningless I think.
>
>Tony S.
>
>"Aleksey" <[email protected]> wrote in message 
>news:[email protected]
>> The question was: how to do this without getting OutOfRange or any other
>> Exception. This is a VERY BAD practice. One should never through 
>> exceptions
>> casually - they consume resources and slow down execution. Thanks for your
>> advice, but there must be a right way to verify if a subscriber exists.
>>
>> Aleksey
>>
>>
>> "TonyS" wrote:
>>
>>> I thought I had posted this snippet that helps with your query
>>>
>>> Tony S.
>>> Public Function IsExistingSubscriber(ByVal subscriberId As String) As
>>> Boolean
>>>
>>> Dim Instance As New NSInstance(Me.sdm_InstName)
>>>
>>> Dim Application As New NSApplication(Instance, Me.sdm_AppName)
>>>
>>> If Not instance Is Nothing Then
>>>
>>> Dim subscriber As Subscriber
>>>
>>> Dim subscriberEnumeration As SubscriberEnumeration
>>>
>>> subscriberEnumeration = New SubscriberEnumeration(instance)
>>>
>>> Try
>>>
>>> subscriber = subscriberEnumeration(subscriberId)
>>>
>>> Return True
>>>
>>> Catch ex As IndexOutOfRangeException
>>>
>>> IsExistingSubscriber = False
>>>
>>> Catch ex As Exception
>>>
>>> IsExistingSubscriber = False
>>>
>>> End Try
>>>
>>> Else
>>>
>>> Return False
>>>
>>> End If
>>>
>>> End Function
>>>
>>>
>>>
>>> "Aleksey" <[email protected]> wrote in message
>>> news:[email protected]
>>> > What is the right way to check if a subscriber exists already?
>>> > Subscriber.Add() raises an error if the ID is already there, and
>>> > SubscriberEnumeration raises an error if it is not there.
>>> > How can I do that without errors? I cannot find a method or property 
>>> > for
>>> > that...
>>> >
>>>
>>>
>>> 
>

<Prev in Thread] Current Thread [Next in Thread>