Solved

Handled Exception Stops Service On Windows 2008 Server

Posted on 2011-02-18
8
661 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:Borsec
  • 4
  • 2
  • 2
8 Comments
 
LVL 10

Expert Comment

by:John Claes
ID: 34924717
Borsec:

can I see the ErroHandling of that TimeOut errorhandling ?
0
 

Author Comment

by:Borsec
ID: 34924906
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
0
 
LVL 6

Expert Comment

by:t-max
ID: 34924964
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
0
 

Author Comment

by:Borsec
ID: 34925017
we have tried this before and it's working, but we are looking for other solution.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 10

Accepted Solution

by:
John Claes earned 500 total points
ID: 34925610
Borsec.

You Should add the folowing part behind EVERY catch


Finally
{
      ftpClient.Close();
      return ;
}


First some info about this

The Finaly code is ran after the Catch and you can do some Cleanup
first we Close the ftpClient bacause some error has occured using it and it's corrupt.
So an other usage will return the same issue.
Then we get out of the Methode calling it so no further lines are used



==>

private sendFile (FileInfo file)
{
      FtpClient ftpClient = new FtpClient();
      ftpClient.Timeout = 60;
      try
      {
            ftpClient.Connect(Server);
      }
      catch (Exception ex)
      {
            "Could not connect to the host: " + Server;
      }
      finally
      {
            ftpClient.Close();
            return ;
      }
      try
      {
            ftpClient.Login(User, Password);
      }
      catch (Exception ex)
      {
            "Could not Login with user: " + User;
      }
      finally
      {
            ftpClient.Close();
            return ;
      }
      try
      {
            ftpClient.SendFile(file.FullName, file.Name);            
      }
      catch(Exception ex)
      {
            "Error occured during Sending File " + ex.Message;
      }
      finally
      {
            ftpClient.Close();
            return ;
      }

}

regards
poor beggar
0
 
LVL 10

Expert Comment

by:John Claes
ID: 34940995
@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
0
 
LVL 6

Expert Comment

by:t-max
ID: 34941582
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!
0
 
LVL 10

Expert Comment

by:John Claes
ID: 34941807
@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
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now