Trying to contact Shyam Pather

I am giving my users the ability to disable their account from my NS front-end web app and to do that I am using the NS API.

In order to disable the subscriber account, I
- instantiate a Subscriber object for the subscriber
- set its Enabled property to False
- call the Update() method

The problem is, when I create another Subscriber instance for the same subscriber somewhere else and check the subscriber.Enabled() property, it always returns True (even if I restart the app), whereas the database is showing that the subscriber account is disabled. Any idea why this is happening?

[610 byte] By [PinalPatel] at [2008-1-28]
# 1

Hi Pinal -

This code snippet demonstrates how to use the SubscriberEnumeration object to retrieve a subscriber object and view its Enabled property in a Label.

private void button1_Click(object sender, System.EventArgs e)
{
//the subscriber id we will work with
string subId = "joew@webbtechsolutions.com";

//Create an NSInstance object
string instanceName = "myNotifyInstance";
NSInstance instance;
instance = new NSInstance(instanceName);

//create disable an existing subscriber
Subscriber subscriber =new Subscriber(instance);
subscriber.SubscriberId = subId;
subscriber.Enabled = false;
subscriber.Update();

//create a new subscriber object
Subscriber subscriber2 = new Subscriber(instance);

//set the subscriberId
subscriber2.SubscriberId = subId;

//Create a SubscriberEnumeration object
SubscriberEnumeration subscribers = new
SubscriberEnumeration(instance);

//retrieve the subscriber object
subscriber2 = subscribers[subId];

//check the enabled property
label1.Text = subscriber2.Enabled.ToString();


}

HTH....

--
Joe Webb
SQL Server MVP


~~~
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)

JoeWebb at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Notification Services...
# 2

Could you post a snippet of your code? I'm surprised this is happening- the API should not reflect a different value than you see in the database.
-shyam

ShyamPather at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Notification Services...
# 3

Hi Shyam -

I think that the following code snippet (v2.0) may reproduce what Pinal was experiencing.
If so, the main issue seems to be in the GetSubscriptions method. Intuitively, one may be likely to think that calling the function would populate the subscriber object - including the Enabled value, however in this case it doesn't seem to do that, leaving the default value of true in place. (I could not find anywhere in BOL that said that it would.)
private
void button1_Click(object sender, System.EventArgs e)

{

//the subscriber id we will work with
string subId = "joe@webbtechsolutions.com";

//Create an NSInstance object
string instanceName = "myNotify";
NSInstance instance;

instance = new NSInstance(instanceName);

//create disable an existing subscriber
Subscriber subscriber =new Subscriber(instance);
subscriber.SubscriberId = subId;
subscriber.Enabled =
false;
subscriber.Update();

//create a new subscriber object
Subscriber subscriber2 = new Subscriber(instance);

//set the subscriberId
subscriber2.SubscriberId = subId;

//use the GetSubscriptions to retrieve the subscriber object
SubscriptionEnumeration subscriptions = subscriber2.GetSubscriptions(
new NSApplication(instance, "myApp"), "mySubscription");

//check the enabled property
label1.Text = subscriber2.Enabled.ToString();

}
--
Joe Webb
SQL Server MVP


~~~
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)

JoeWebb at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Notification Services...
# 4
Joe is right. This is exactly what I was doing and that's why I was getting incorrect result. Thank you very much Joe for the clarification!
PinalPatel at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Notification Services...
# 5
OK, I see the problem. You are creating a new subscriber object to represent the existing subscriber, but nowhere is that object being initialized from the database. The GetSubscriptions object does not initialize the subscriber object.

Instead of creating a new objects, you should retrieve a subscriber object for the existing subscriber from the SubscriberEnumeration. This will obtain the correct values from the database.

The code would look something like this (it may be a little off because I'm typing this from memory - I'm not at a setup where I can test this right now):

SubscriberEnumeration subscribers = new SubscriberEnumeration(nsInstance);
Subscriber existingSubscriber = subscribers["exstingSubscriberId"];

if there is no existing subscriber with the id you pass to the indexer ("existingSubscriberId", in my example), the call will throw an IndexOutOfRangeException.

Hope this helps.
-shyam

ShyamPather at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Notification Services...
# 6
Shyam, I would like to get in contact with you. I am with a tech company in Florida that is totally a Microsoft house, particularlly MS SQL. Would it be possible for you to e-mail me when you have a chance? holly.pauline@channelintelligence.com. Thank you!
Holly at 2007-9-9 > top of Msdn Tech,SQL Server,SQL Server Notification Services...

SQL Server

Site Classified