Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal connection fatal error

I've recently started receiving this error: "Internal connection fatal error" from my application. The error occurs randomly. When it happens my application is unusable for the next few minutes.

After careful analysis of the error I've concluded that this error happens in only one method within my application. This method fires a series of simple ordinary SQL queries but it does involve multithreading however all threads should be disposed before this block of code. The error happens always on a specific SQL query. For test I've eliminated this query which resulted in error happening on next in line query.

This is stack strace:

Internal connection fatal error.

-------------- Stack trace ---------------
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.IntentionalRethrow(Exception chainException, Exception originalException)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.RethrowRecommended(Exception chainException, Exception originalException)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyEntry.Handle(Exception exceptionToHandle)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl.HandleException(Exception exceptionToHandle)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName, ExceptionPolicyFactory policyFactory)
   at Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicy.HandleException(Exception exceptionToHandle, String policyName)
   at Base.Sql.ExecuteScalar()

Application is built on .NET 3.5 and it obviously uses Enterprise Library Data Access. Application is run on Win2003 Terminal Server and it's using Sql Server 2005 database which is on different server.

The method which causes this error is not triggered from GUI but from command line if that is of any significence.

If someone would suggest where to go from here I would be very grateful.

like image 355
Nezreli Avatar asked Jul 11 '12 10:07

Nezreli


2 Answers

I faced the similar issue and have devoted quite a time on this issue. So you need to check for all of the following one by one.

  1. You might have left some open connection to database just before giving a call to stored procedure.
  2. This exception comes while calling SqlDataReader.Close() or SqlDataReader.Dispose() - It can be fixed using SqlConnection.Close() instead of SqlDataReader.Close()
  3. Delete your temp files folder?
  4. Look at the usage of the ephemeral ports by the IIS server. The default max no. of ports available is normally 4000. You can increase it if your application is making a lot of database calls.

Let me know if it didn't helped. I might get a chance to learn something new.

like image 95
NG. Avatar answered Sep 29 '22 17:09

NG.


Weird errors like this are often the result of multi-threading access to objects that are not threadsafe.

I think a couple of things are going wrong here.

  • reuse of open connection across the threads.
  • reuse of sql client objects across the threads.
  • not closing open connections correctly - are you wrapping your connection creation with a using?

Provide a code example and we might be able to spot the problem...

like image 41
Chris Moutray Avatar answered Sep 29 '22 18:09

Chris Moutray