Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Handled Exception Stops Service On Windows 2008 Server

Posted on 2011-02-18
8
Medium Priority
?
690 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
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…

618 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