question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Firebird ADO.NET-Provider connection pool error on connection lost

See original GitHub issue

First, this is not a linq2DB error, it is a tip for a workaround caused by the current Firebird ADO.NET provider (Version 4.6.0.0 - 5.12.1.0) If you are working with connection pools and your connection is lost e.g. because the Firebird server is closed, the pooled connection is still marked as ‘opened’. So every database access will create an Exception (FBException) ‘Error reading data from the connection’. So if the Firebird server is accessible again you still cannot access it because the old connection will be used!

One solution is to disable pooling. I don’t like this because of performance reduction.

Another solution is to handle it in the OnTrace Action.:

DataConnection.OnTrace = delegate(TraceInfo info)
		{
			try
			{
				// First time access, if no connection has been ever established, this will throw an error!
				var conn = (FbConnection)info.DataConnection?.Connection;

				var fbException = info.Exception as FbException;
				// The error code stands for 'Error reading data from the connection'
				if (fbException != null && fbException.ErrorCode == 335544726)
				{
					// Clear all pooled connections, because the connection to the database is lost!
					FbConnection.ClearAllPools();
				}
			}
			catch (Exception ex)
			{
				// No database connection was ever opened!
				return;
			}
		};

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
frankiDotNetcommented, Mar 14, 2018

This works:

	/// <summary>	A Firebird retry policy. </summary>
	public class FbRetryPolicy : RetryPolicyBase
	{

		/// <summary>	Not try again error codes, that clears the connection pool. </summary>
		public static List<int> NotTryAgainErrorCodes = new List<int>()
		{
			335544726, //	read_err
			335544721, //	network_error
			335544421, //	connect_rejec
		};
		
		/// <summary>	Default constructor. </summary>
		public FbRetryPolicy() : base(Configuration.RetryPolicy.DefaultMaxRetryCount, Configuration.RetryPolicy.DefaultMaxDelay) { }

		/// <summary>	Constructor. </summary>
		/// <param name="maxRetryCount">	Number of maximum retries. </param>
		/// <param name="maxRetryDelay">	The maximum retry delay. </param>
		public FbRetryPolicy(int maxRetryCount, TimeSpan maxRetryDelay) : base(maxRetryCount, maxRetryDelay) { }
		

		/// <summary>
		/// Determines whether the specified exception represents a transient failure that can be
		/// compensated by a retry.
		/// </summary>
		/// <param name="exception">	The exception object to be verified. </param>
		/// <returns>
		/// <c>true</c> if the specified exception is considered as transient, otherwise <c>false</c>.
		/// </returns>
		protected override bool ShouldRetryOn(Exception exception)
		{
			FbException fbException = exception as FbException;
			// The error code stands for 'Error reading data from the connection'
			if (fbException != null && NotTryAgainErrorCodes.Contains(fbException.ErrorCode))
			{
				// Clear all pooled connections, because the connection to the database is lost!
				FbConnection.ClearAllPools();
				return false;
			}
			return true;
		}
	}

In your context costructor just call:

this.RetryPolicy = new FbRetryPolicy();

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error MaxPoolSize on Firebird database
In connection to the database I use a pool of connections and Firebird database. I use FirebirdSql.Data.FirebirdClient version 2.6.5.0.
Read more >
ADO.NET Connection Pooling with C# Code Examples ...
This tutorial describes how reusing pooled connections, instead of creating new connections, can improve .NET application performance.
Read more >
14.2 Connections Pool Management
Configures the maximum number of idle connections in the pool. The default value is set using the parameter ExtConnPoolSize in firebird. conf ....
Read more >
FirebirdSql.Data.Common.IscException: Error writing ...
This error happens when the firebird server crashes or some network interruption. Connection pooling usually makes this worse since it keeps old connections ......
Read more >
Idle database connection lost - linux
When operating interactively using Firebird Maestro (relevance unknown), after I get this error I tell Maestro to disconnect. I am then able to ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found