SMO Sample: Enable TCP/IP Server protocol of SQL Server 2005


Purpose of sample: Enable the TCP/IP server protocol.

 

This sample shows you how to change a server protocol setting. This sample assumes you have SQL Express installed. You need to change the instance name to match the instance name you have installed.

 


ManagedComputer mc = new ManagedComputer();


mc.ServerInstances["SQLEXPRESS"].ServerProtocols["Tcp"].IsEnabled = true;

Comments (4)

  1. Hi,

    I tried this code, it doesn’t throw any error. But still the SQL server Configuration manager shows, disabled.

    Could you help!

    Best Regards,

    DHAKCHINA MOORTHY.C

  2. ionymous says:

    I too have been trying this.  But TCP/IP remains disabled.

    Trying different wrong server names crashes my code… which implies I am using the right server name.

    Don’t know why it isn’t working.

  3. ionymous says:

    Wait, I think I figured it out.

    Calling the Alter method on ServiceProtocol object after making the change worked for me.

    Wmi.ManagedComputer mc = new Wmi.ManagedComputer();

    Wmi.ServerProtocol sp = mc.ServerInstances["SQLEXPRESS"].ServerProtocols["Tcp"].IsEnabled = true;

    sp.Alter();

  4. ionymous says:

    Oops…  I combined a line there… should be:

    Wmi.ManagedComputer mc = new Wmi.ManagedComputer();

    Wmi.ServerProtocol sp = mc.ServerInstances["SQLEXPRESS"].ServerProtocols["Tcp"];

    sp.IsEnabled = true;

    sp.Alter();

Skip to main content