issues using try and catch with a wmi request on a remote machine.

May 6 2009 5:55 AM

Hi,

I am creating an asp.net app using C# to list and manage windows services on remote machines.

When I do not use the try and catch method. The function works fine, but when I do use it I get the following error.
The transport failed to connect to the server.

However this is only the issue on servers that have a slow reponse time. Servers that have a normal response time do not have this issue.

How can I make sure that this error is not thrown and still use the try catch method to catch other errors like permissions?

Code:

try
{
ServiceController[] oArrServices;
oArrServices = ServiceController.GetServices(txtServer.Text.Trim());
ArrayList MyTable = new ArrayList();
MyTable.Add(
" Choose a Service");
foreach (ServiceController oSC in oArrServices)
{
myTable.Add(oSC.DisplayName)
}
MyTable.TrimToSize();
MyTable.Sort();
dropdown1.DataSource = MyTable;
dropdown1.DataBind();
}
catch

{
ErrorLabel.Text = ex.Message;
}


Answers (1)