Showing posts with label samples. Show all posts
Showing posts with label samples. Show all posts

Friday, March 9, 2012

Programmatically Deleting an Instance

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

Monday, February 20, 2012

Programatically create replication publication?

Is it possible to create a publication entirely from within my application?
If so, are there some samples or documentation anyone can point me to?
Thanks in advance,
Terry
Terry,
please have a look at the SQLDMO and ActiveX scripts on this page:
http://www.replicationanswers.com/Scripts.asp.
Also, you might want to investigate creating a replication setup in a test
environment, having enterprise amnager script out the setup, modifying it
then using this as a starting point for your setup. This would achieve the
same ends, but be entirely in TSQL.
Cheers,
Paul Ibison SQL Server MVP, www.replicationanswers.com
(recommended sql server 2000 replication book:
http://www.nwsu.com/0974973602p.html)
|||Hello Terry,
If you are using SQL 2005, you may need to consider RMO
Programming with Replication Management Objects
http://msdn2.microsoft.com/en-us/library/ms146869.aspx
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
--
>From: "Paul Ibison" <Paul.Ibison@.Pygmalion.Com>
>References: <OXitg7E9FHA.3020@.TK2MSFTNGP09.phx.gbl>
>Subject: Re: Programatically create replication publication?
>Date: Mon, 28 Nov 2005 19:31:30 -0000
>Lines: 13
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
>X-RFC2646: Format=Flowed; Response
>Message-ID: <uT77YJF9FHA.3880@.TK2MSFTNGP12.phx.gbl>
>Newsgroups: microsoft.public.sqlserver.replication
>NNTP-Posting-Host: 82-43-215-101.cable.ubr10.newm.blueyonder.co.uk
82.43.215.101
>Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP12.phx.gbl
>Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.replication:67037
>X-Tomcat-NG: microsoft.public.sqlserver.replication
>Terry,
>please have a look at the SQLDMO and ActiveX scripts on this page:
>http://www.replicationanswers.com/Scripts.asp.
>Also, you might want to investigate creating a replication setup in a test
>environment, having enterprise amnager script out the setup, modifying it
>then using this as a starting point for your setup. This would achieve the
>same ends, but be entirely in TSQL.
>Cheers,
> Paul Ibison SQL Server MVP, www.replicationanswers.com
> (recommended sql server 2000 replication book:
> http://www.nwsu.com/0974973602p.html)
>
>
|||Thanks guys ...
Your suggestions look like my answers.
Tery
"Peter Yang [MSFT]" <petery@.online.microsoft.com> wrote in message
news:HNKee6K9FHA.4000@.TK2MSFTNGXA02.phx.gbl...
> Hello Terry,
> If you are using SQL 2005, you may need to consider RMO
> Programming with Replication Management Objects
> http://msdn2.microsoft.com/en-us/library/ms146869.aspx
> Best Regards,
> Peter Yang
> MCSE2000/2003, MCSA, MCDBA
> Microsoft Online Partner Support
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ================================================== ===
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>
> --
> 82.43.215.101
>
|||Hello Terry,
My pleasure! :-)
Best Regards,
Peter Yang
MCSE2000/2003, MCSA, MCDBA
Microsoft Online Partner Support
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
================================================== ===
This posting is provided "AS IS" with no warranties, and confers no rights.
--
>From: "Tery" <justme@.noemail.noemail>
>References: <OXitg7E9FHA.3020@.TK2MSFTNGP09.phx.gbl>
<uT77YJF9FHA.3880@.TK2MSFTNGP12.phx.gbl>
<HNKee6K9FHA.4000@.TK2MSFTNGXA02.phx.gbl>
>Subject: Re: Programatically create replication publication?
>Date: Tue, 29 Nov 2005 08:55:11 -0600
>Lines: 68
>X-Priority: 3
>X-MSMail-Priority: Normal
>X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
>X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
>X-RFC2646: Format=Flowed; Original
>Message-ID: <uh0JjTP9FHA.2192@.TK2MSFTNGP14.phx.gbl>
>Newsgroups: microsoft.public.sqlserver.replication
>NNTP-Posting-Host: dsl-201-155-245-16.prod-empresarial.com.mx
201.155.245.16[vbcol=seagreen]
>Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP14.phx.gbl
>Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.sqlserver.replication:67058
>X-Tomcat-NG: microsoft.public.sqlserver.replication
>Thanks guys ...
>Your suggestions look like my answers.
>Tery
>"Peter Yang [MSFT]" <petery@.online.microsoft.com> wrote in message
>news:HNKee6K9FHA.4000@.TK2MSFTNGXA02.phx.gbl...
test[vbcol=seagreen]
the
>
>