I'm trying to just get a basic NS app up and running. While I can get through the samples just fine, it seems there are no samples that programmatically manage Instances/Applications, etc. I've googled around and not found anything either. Essentially it looks to me that everyone uses the IDF/ADF files. The SDK has some very sparse documentation on it, so I've started there and tried to get things working.
I have code to create the instance/application programmatically, but when I want to drop the whole thing and create it again, upon calling instance.Create() I get an exception (actually this is what the innerException says) saying:
Notification Services failed to read the NSVersionInfo table.
I’m following the example in the SDK (doing Disable/UnregisterLocal/Drop). Interestingly when I do the Disable/Unregister/Drop in SQL Management Studio it works fine. It's also interesting to note that when I ignore the exception it comes up once more, but after that the instance and associated databases seem to be created.
Here’s the short version of my code (getFreshInstance() is the entry method):
private void configureInstance(nmo.Instance instance)
{
prototypeApplication = new nmo.Application(instance, applicationName);
AddDeliveryChannels(instance);
configureApp(prototypeApplication);
instance.Applications.Add(prototypeApplication);
}
private void configureApp(nmo.Application app)
{
AddGenerator(app);
AddDistributor(app);
}
private void checkAndDrop(string name)
{
if (notificationServices.Instances.Contains(name))
{
nmo.Instance instance = new nmo.Instance(notificationServices, name);
instance.Refresh();
instance.Disable();
instance.UnregisterLocal();
instance.Drop();
}
}
private nmo.Instance getFreshInstance()
{
nmo.Instance instance = new nmo.Instance(notificationServices, instanceName);
checkAndDrop(instanceName);
configureInstance(instance);
instance.Create();
instance.RegisterLocal();
instance.Enable();
return instance;
}
Anyone know what I'm doing wrong?
Ok, seems you've asked a question not many folks in the wild know the answer to :-).
I've tracked down what is probably the answer care of Shyam Pather:
He’s creating a new in-memory object to reflect his instance, like this:
Nmo.Instance instance = new Nmo.Instance(…, “InstanceName”);
Instead, he should do something like:
Smo.Server s = new Smo.Server(…);
Nmo.Instance instance = s.NotificationServices.Instances[“InstanceName”];
That will get him an instance object that’s already populated with the metadata from the database and actually represents the existing instance.
The FlightNMO sample that comes with SQL Server 2005 should also provide you a working example of how to make the API calls.
Hope that helps,
-Lukasz
This posting is provided "AS IS" with no warranties, and confers no rights.
I just gave that snippet a try and unfortunately, I ended up with the same error when I attempt to enable. The need for this functionality in my project has been removed by a change in design, so I'm no longer really worried about this, but I would still be curious to know the cause of this or hear confirmation of someone else running into this.
Now that you mention it, I vaguely remember seeing the FlightNMO sample when I first looked at NS, but had since forgotten it. Thanks! I'm sure that'll prove quite useful later. As far as this particular functionality though, I'm afraid FlightNMO doesn't ever delete the instance, only create.
Thanks for your help,
-Francis
No comments:
Post a Comment