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...
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.
4 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.
- You might have left some open connection to database just before giving a call to stored procedure.
- This exception comes while calling SqlDataReader.Close() or SqlDataReader.Dispose() - It can be fixed using SqlConnection.Close() instead of SqlDataReader.Close()
- Delete your temp files folder?
- 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.
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...
I and my team have been baffled by this problem for quite sometime. We tried implementing everything , from the try-catch-finally to maintenance of all the coding standards; however this problem kept on occurring whenever multiple users were trying to access the page at the same time. The connection would be broken and problems were arising.At times we even have to restart the entire server for the application to start working. Problem was we were unable to restrict users from using the same connection string thus throwing this error. Ultimately we tried opening and closing the connectionstring with "using", previously we were opening and closing it manually with "dbcon.opne()" and "dbcon.close()", after the dataadapter was able to fetch the data.
So what we did, we replaced the same thing with "using" and that kept the whole thing within bracket.
using (DBConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnect"].ConnectionString)) { the code here --- if (DBConn.State != ConnectionState.Open) DBConn.Open();
}
This resolved the problem completely.
Hope this helps.
For .NET Core 2.0 or higher, the the error can also occur when you have the following in your .csproj file:
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />
</ItemGroup>
According to the documentation, this option "enables you to remove application dependencies on globalization data and globalization behavior." Apart from smaller file size, I don't know what the benefits of that are, but SqlConnection doesn't work with it.