Welcome to MSDN Blogs Sign in | Join | Help

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;

Published Friday, February 10, 2006 5:09 PM by mwories
Filed under:

Comments

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

Thursday, September 13, 2007 6:38 PM by cdm@shss.co.in

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

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

Friday, March 28, 2008 9:09 AM by ionymous

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.

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

Friday, March 28, 2008 9:32 AM by ionymous

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();

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

Friday, March 28, 2008 9:38 AM by ionymous

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();

Anonymous comments are disabled
 
Page view tracker