Good, glad you found it. FWIW - Here is a bit more of the C# snippet I
use to create a subscription. It's not in VB but translating shouldn't
be much of a chore.
private void createButton_Click(object sender, System.EventArgs e)
{
//make sure we have all the information we need
if (scheduledRadio.Checked == true)
{
if(timeZoneCombo.SelectedIndex == -1)
{
tzError.SetError(timeZoneCombo, "Please select a time zone.");
return;
}
}
//Create an NSInstance object
NSInstance instance;
instance = new NSInstance(MyInstanceName);
//Create an NSApplication object
NSApplication app;
app = new NSApplication(instance, MyAppName);
//create a subscription object
Subscription newSubscription;
newSubscription = new Subscription(app, MySubscriptionClass);
//assign its properties
newSubscription.Enabled = true;
newSubscription.SubscriberId = MySubscriberId;
//newSubscription["DeviceName"] = deviceNameText.Text;
//newSubscription["SubscriberLocale"] = "en-us";
//assign the subscription fields
foreach(Control ctl in fieldsPanel.Controls)
{
if (Convert.ToString(ctl.Tag) != "")
newSubscription[Convert.ToString(ctl.Tag)] = ctl.Text;
}
//subscription type
if (scheduledRadio.Checked == true)
{
//daily occurrence
newSubscription.ScheduleRecurrence = "FREQ=DAILY;";
//what time zone?
string tz = timeZoneCombo.SelectedItem.ToString();
int p1 = tz.IndexOf("(") + 1;
int p2 = tz.IndexOf(")");
int len = p2 - p1;
short tzid = Convert.ToInt16(tz.Substring(p1, len));
//build the schedule start string
System.Text.StringBuilder sched = new System.Text.StringBuilder() ;
sched.Append("TZID=");
sched.Append(tzid.ToString());
sched.Append(":");
sched.Append(DateTime.Now.ToString("yyyyMMdd"));
sched.Append("T");
sched.Append(timePicker.Value.Hour.ToString("00"));
sched.Append(timePicker.Value.Minute.ToString("00"));
sched.Append("00");
newSubscription.ScheduleStart = sched.ToString();
}
//add the subscription to the application database
try
{
newSubscription.Add();
}
catch (Exception eNewSub)
{
//catch the error and process
MessageBox.Show(eNewSub.ToString(), "SQLNS Test Application",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
//close
this.Close();
this.Dispose();
}
HTH...
Joe Webb
SQL Server MVP
~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811 [quoted text, click to view] tarpan wrote:
> Yes.
>
> I just found that the problem is. I did not assign values
> to the fields (items).
>
>
>
>>-----Original Message-----
>>Tarpan -
>>
>>Are you initializing the instance and application objects
>
> first?
>
>>Here's is a snippet of C# code from a sample subscription
>
> management
>
>>application. The full blown application is available for
>
> free download
>
>>on my web site,
www.webbtechsolutions.com, under the
>
> downloads section.
>
>>//Create an NSInstance object
>>NSInstance instance;
>>instance = new NSInstance(MyInstanceName);
>>
>>
>>//Create an NSApplication object
>>NSApplication app;
>>app = new NSApplication(instance, MyAppName);
>>
>>
>>//create a subscription object
>>Subscription newSubscription;
>>newSubscription = new Subscription(app,
>
> MySubscriptionClass);
>
>>
>>
>>
>>HTH...
>>Joe Webb
>>SQL Server MVP
>>
>>~~~
>>Get up to speed quickly with SQLNS
>>
http://www.amazon.com/exec/obidos/tg/detail/-/0972688811 >>
>>
>>
>>
>>tarpan wrote:
>>
>>>Hi,
>>>
>>>The NS API throws the following exeption:
>>>
>>>Microsoft.SqlServer.NotificationServices.NSException:
>
> The
>
>>>subscription object has not been initialized.
>>>InstanceName: ELSInstance ApplicationName: ELS
>>>SubscriptionClassName: ELS_Bin_Level_CSubscription
>>>SubscriberId: Oleksiy SubscriptionId: 0
>>>
>>>The code is:
>>>
>>>Dim Subscription As New Subscription
>>>
>>>Subscription.Initialize(NSApplication,
>>>SubscriptionClassName)
>>>Subscription.SubscriberId = UserName
>>>Subscription.Add()
>>>
>>>What is wrong?
>>
>>.