Link to home
Start Free TrialLog in
Avatar of Borsec
BorsecFlag for Romania

asked on

Handled Exception Stops Service On Windows 2008 Server

I have a service running on a Windows 2008 Server. The service, using the Xceed FTP component, opens an FTP connection to a remote server and uploads a file. Sometimes a timeout exception is thrown. Altough the exception is handled by the service and is written its log file few second later Windows stops the service. In the Eventlog an entry From Windows Error Reporting with the same Timeout exception is written.

If the FTP component cannot open the connection (wrong PWD for example) an exception is also thrown but in this case the service continues its execution.

Disabling the Windows Error Reporting is not an option.
Avatar of John Claes
John Claes
Flag of Belgium image

Borsec:

can I see the ErroHandling of that TimeOut errorhandling ?
Avatar of Borsec

ASKER

FtpClient ftpClient = new FtpClient();
ftpClient.Timeout = 60;
try
{
      ftpClient.Connect(Server);
}
catch (Exception ex)
{
      "Could not connect to the host: " + Server;
}
try
{
      ftpClient.Login(User, Password);
}
catch (Exception ex)
{
      "Could not Login with user: " + User;
}
 try
{
      ftpClient.SendFile(file.FullName, file.Name);            
}
catch(Exception ex)
{
}

Error message:
1.  An I/O error occurred while accepting the FTP server's data connection.
Xceed.Ftp.FtpIOException: An I/O error occurred while accepting the FTP server's data connection. ---> System.Net.Sockets.SocketException: Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat IP:PortNr
   bei System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
   bei Xceed.Ftp.Engine.PassiveFtpDataChannel.ConnectCompleted(IAsyncResult asyncResult)
   bei Xceed.Ftp.Engine.FtpCommandSequence.EndExecute(IAsyncResult asyncResult)
   bei Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
   bei Xceed.Ftp.FtpClient.DoGetFolderContents(FtpCommandChannel commandChannel, ListFtpCommand listCommand)
   bei Xceed.Ftp.FtpClient.GetFolderContents(String remoteFileMask)
   
2. An error occurred while connecting to the FTP server.
Xceed.Ftp.FtpIOException: An error occurred while connecting to the FTP server. ---> System.Net.Sockets.SocketException: Ein Verbindungsversuch ist fehlgeschlagen, da die Gegenstelle nach einer bestimmten Zeitspanne nicht richtig reagiert hat, oder die hergestellte Verbindung war fehlerhaft, da der verbundene Host nicht reagiert hat Ip:PortNr
   bei System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   bei System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   bei Xceed.Ftp.Engine.FtpCommandChannel.Connect(IPEndPoint localAddress, IPEndPoint remoteAddress)
   --- Ende der internen Ausnahmestapelüberwachung ---
   bei Xceed.Ftp.Engine.ConnectFtpCommand.EndExecute(IAsyncResult asyncResult)
   bei Xceed.Ftp.FtpClient.DoExecuteCommand(FtpCommandChannel commandChannel, BaseFtpCommand command)
   bei Xceed.Ftp.FtpClient.DoConnect(FtpCommandChannel commandChannel, ConnectFtpCommand command)
   bei Xceed.Ftp.FtpClient.Connect(String hostName)
   ...
   Could not connect to the host: Server
Perhaps a script to check the service status (and restart it if stopped) is what you need?
http://www.techrepublic.com/forum/questions/101-274860
Avatar of Borsec

ASKER

we have tried this before and it's working, but we are looking for other solution.
ASKER CERTIFIED SOLUTION
Avatar of John Claes
John Claes
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@Borsec:

Do you have any progress?

@t-max:
Restarting a Service when it's not running is not a solution only a Dirty Bug-Fix
You should always try to find the reason :

The reason here is that when he's try fails the we fly through the Catch and leave a broken connection let it dispose itself. (--> broken -> do something itself ???)


regards
poor beggar
I agree with you poor beggar. However if the service wasn't written by you, and there's nothing wrong on your side, the only possible course of action is to restart the service until you figure out something else (changing software, talking to support for a solution, etc).
My solution was a simple workaround if the other stuff fails, but  I didn't say that before, so thanks for the constructive critic. All the best!
@t-max:
At that point you're right ;-)
If you don't have the code there is indeed no other way ;-(

Sorry If i seemed to be Rude
regards
poor beggar