Solved

Handled Exception Stops Service On Windows 2008 Server

Posted on 2011-02-18
8
670 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Borsec
ID: 34925017
we have tried this before and it's working, but we are looking for other solution.
0
 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 129
orderby list (from Json) 1 42
PowerShell: ForEach-Object Export to CSV 4 89
What is needed to become a DBA? 7 49
Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
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…

737 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