Tuesday, 20 March 2012

Connect to an NS instance on remote server

I have Sql Server 2005 and Notification Services on one machine and I am developing a web app on another machine that will be front-end to the NS instance. So far all the examples I've seen for connecting to an instance using NS API assume that Sql Server, Notification Services and the development environment are on the same machine. Is it possible to connect to an instance on a remote machine using NS API? If so, how can it be done?

On the machine hosting your web app, you'll need to register the NS instance. When you register instance, you specify the name of the database server hosting the NS instance and the sql username/password used to connect to it, if you're using sql auth. Once you've created the registration, you can then use the NS API just like you would if the sql server were local: you create an instance of the NSInstance class, passing the instance name. The NSInstance implementation will read the server/connection information from the registry.

To register the instance, you have two options:
- On the web server machine, run nscontrol register, passing the name of your SQL Server (not the local machine) to the -server parameter.
- On the web server machine, run SQL Server Management Studio, connect the Object Explorer to the SQL Server hosting your instance's databases, right click on the instance name in the Notification Services folder and choose "Register" from the context menu.

Whichever tool you choose (nscontrol or management studio), you must run it locally on the web server box.
Hope this helps.
-shyam

|||Shyam is right that you need to register the instance.

There is also a third option to do the registration:
- You can use the Microsoft.SqlServer.Management.Nmo.Instance.RegisterLocal method to do the registration at runtime. There are class and instance based overloads that you can choose from to meet your needs. As the name suggests, you have to execute it on the locally on the web server box.

Whether you choose to do your registration at runtime or as part of your deployment steps (using the options Shyam mentions) you have to do it before you initialize the NSInstance object.

Hope that helps.
Anand

No comments:

Post a Comment