SocketException from code not caught in try catch or Application_Error

M

mc

I have a function (shown below) that I call to check if a server is present. when a server is
present, everything is ok. however when it fails. I get an SocketException fired. On my development
machine all seems to work and the exception is fired and caught. however on my production server the
exception fires, it's not caught by the try catch and it's also not caught in my application_error
handler in Global.asax. Can anyone shed any light on this?

private bool CheckServer(string p){
try{
using (Socket s = new Socket(AddressFamily.Internetwork, SocketType.Stream, ProtocolType.Tcp)){
IPEndPoint iep = new IPEndPoint(DNS.GetHostEntry(p).AddressList[0], 80);
s.Connect(iep);
return true;
}
}
catch{
return false;
}
}

TIA


MC
 
A

Aidy

It might be something to do with the fact that you're using "using" inside a
try block. Try it without the "using".
 
B

bruce barker

most likely the page request is timing out before the socket connection
timeout. explicity set the values.

-- bruce (sqlwork.com)
 
M

mc

No change! still broke.
Aidy said:
It might be something to do with the fact that you're using "using" inside a
try block. Try it without the "using".

I have a function (shown below) that I call to check if a server is
present. when a server is present, everything is ok. however when it fails.
I get an SocketException fired. On my development machine all seems to work
and the exception is fired and caught. however on my production server the
exception fires, it's not caught by the try catch and it's also not caught
in my application_error handler in Global.asax. Can anyone shed any light
on this?

private bool CheckServer(string p){
try{
using (Socket s = new Socket(AddressFamily.Internetwork,
SocketType.Stream, ProtocolType.Tcp)){
IPEndPoint iep = new IPEndPoint(DNS.GetHostEntry(p).AddressList[0],
80);
s.Connect(iep);
return true;
}
}
catch{
return false;
}
}

TIA


MC
 
S

Steven Cheng[MSFT]

Hi MC,

It is also likely that there is something related to the account running
the application. Is there any proxy that requires to visit the certain
remote server/site? You can try switch the ASP.NET process to a domain
account to see whether it works.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
Date: Tue, 18 Dec 2007 17:26:43 +0000
From: mc <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Re: SocketException from code not caught in try catch or Application_Error

No change! still broke.
Aidy said:
It might be something to do with the fact that you're using "using" inside a
try block. Try it without the "using".

I have a function (shown below) that I call to check if a server is
present. when a server is present, everything is ok. however when it fails.
I get an SocketException fired. On my development machine all seems to work
and the exception is fired and caught. however on my production server the
exception fires, it's not caught by the try catch and it's also not caught
in my application_error handler in Global.asax. Can anyone shed any light
on this?

private bool CheckServer(string p){
try{
using (Socket s = new Socket(AddressFamily.Internetwork,
SocketType.Stream, ProtocolType.Tcp)){
IPEndPoint iep = new IPEndPoint(DNS.GetHostEntry(p).AddressList[0],
80);
s.Connect(iep);
return true;
}
}
catch{
return false;
}
}

TIA


MC
 
S

Steven Cheng[MSFT]

Hi MC,

Have you got progress on this? If still need any help, welcome to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
M

mc

The AppPool Identity for the site in question is already a domain account is this the setting you meant.

Consider this closed as I've moved onto an alternative solution, not perfect but it works.
Steven said:
Hi MC,

It is also likely that there is something related to the account running
the application. Is there any proxy that requires to visit the certain
remote server/site? You can try switch the ASP.NET process to a domain
account to see whether it works.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
Date: Tue, 18 Dec 2007 17:26:43 +0000
From: mc <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Subject: Re: SocketException from code not caught in try catch or
Application_Error

No change! still broke.

inside a

fails.

work

the

caught

light

IPEndPoint(DNS.GetHostEntry(p).AddressList[0],
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top