3

We are working on migrating data from different source systems(Firebird, Oracle, SQL Server) to one target system (SQL Server).

We are getting Error reading data from the connection exception from Firebird connections.

Code we are using

Static DbFactory Class to Create SourceSystem Object

public static class DbFactory
{
    public static DbManager CreateDb(SourceDbType type)
    {
        switch (type)
        {
            case SourceDbType.Sql:
                return new SqlDbManager();
            case SourceDbType.FireBird:
                return new FireBirdDbManager();
        }
        return null;
    }
}

public enum SourceDbType
{
    Sql, FireBird
}

Base DbManager Class

public abstract class DbManager
{
    private DbConnection m_DbConnection;
    public virtual DbConnection DbConnection
    {
        get
        {
            if (m_DbConnection == null)
            {
                m_DbConnection = new SqlConnection();
            }
            return m_DbConnection;
        }
        set
        {
            this.m_DbConnection = value;
        }
    }



    public virtual void SetConnectionString(Migration migration, DataTable dtConnectionDetails = null)
    {
        try
        {
            DbConnection.ConnectionString = string.Format("Server={0};Database={1};User ID={2};Password={3};",
           migration.NetworkPartnerData.Server,
           migration.NetworkPartnerData.Database,
           migration.NetworkPartnerData.User,
          AESEncryptionDecryptionUtility.DecodeBase64(migration.NetworkPartnerData.Password));
        }
        catch
        {

            throw;
        }


    }

    public virtual void SetConnectionString(string connectionString)
    {
        try
        {
            DbConnection.ConnectionString = connectionString;
        }
        catch
        {

            throw;
        }


    }

    public virtual DataTable ExecuteDataTable(string ConnectionString, string queryText)
    {
        throw new NotImplementedException();
    }
}

FireBirdDbManager class inherited from DbManager

 public class FireBirdDbManager : DbManager
{
    private FbConnection fbconnection;
    public override DbConnection DbConnection
    {
        get
        {
            if (fbconnection == null)
            {
                fbconnection = new FbConnection();
            }
            return fbconnection;
        }
        set
        {
            this.fbconnection = value as FbConnection;
        }
    }

    public override void SetConnectionString(Migration migration, DataTable connectionDetails)
    {

        this.DbConnection.ConnectionString = string.Format("Server={0};Database={1};Port=3050;User ID={2};Password={3};Pooling=true;MinPoolSize=0;MaxPoolSize=50;",
            migration.NetworkPartnerData.Server,
            migration.NetworkPartnerData.Database + BuildDatabaseName(Convert.ToString(connectionDetails.Rows[0]["CL_NBR"])) + ApplicationConstants.FIREBIRD_DBFILE_EXTENSION,
            migration.NetworkPartnerData.User,
           iMigrationTool.Common.AESEncryptionDecryptionUtility.DecodeBase64(migration.NetworkPartnerData.Password));
    }
    public override DataTable ExecuteDataTable(string ConnectionString, string queryText)
    {
        using (var connection = new FbConnection(ConnectionString))
        {
            try
            {


                DataTable dt = new DataTable();
                connection.Open();
                using (FbTransaction readTransaction = connection.BeginTransaction(IsolationLevel.ReadCommitted))
                {
                    FbCommand readCommand = new FbCommand();
                    try
                    {
                        readCommand.CommandText = queryText;
                        readCommand.Connection = connection;
                        readCommand.Transaction = readTransaction;
                        FbDataAdapter da = new FbDataAdapter(readCommand);
                        da.SelectCommand.CommandType = CommandType.Text;
                        da.Fill(dt);

                        readTransaction.Commit();
                    }
                    catch
                    {
                        readTransaction.Rollback();
                        throw;
                    }
                    finally
                    {
                        readTransaction.Dispose();
                        if (connection.State == ConnectionState.Open)
                        {
                            connection.Close();
                        }
                        connection.Dispose();
                    }
                    return dt;
                }
            }
            catch (Exception ex)
            {
                int errorCode = ex.HResult;
                Logger.LogApplicationException(ex, null, "ERRORCODE:" + errorCode + "ConnectionString:" + ConnectionString, "MigrationWorker");
                throw ex;
            }
        }
    }
}

Exception Images Exception Image1 Image 2 Image 3 Connection String built

We are getting exception after running 3 to 4 migrations. If I restart the service again we are able to run 3 to 4 migrations.

Code we use to call the respective source systems: Create SourceSytemOjbect

We are very new to Firebird database systems and unable to solve the problem. On a side note we are using Visual Studio 2012, Azure Cloud service

8
  • 2
    "error reading data from the connection" usually means that the connection was closed unexpectedly or otherwise generates low level IO errors. Which Firebird version are you using, and which database connection library and version? Also try disabling connection pooling. Commented Sep 23, 2015 at 10:15
  • @MarkRotteveel Thank you for your inputs . I need to check with Offshore team because we are connecting to Firebird server using FlameRobin Database Admin. we are using Library DLL : FirebirdSql.Data.FirebirdClient and Version: 4.8.0.0, Removed connection pooling and inprocess of testing Commented Sep 23, 2015 at 11:27
  • @MarkRotteveel Still same problem no luck :( Any other suggestions Commented Sep 23, 2015 at 12:06
  • 1
    The only other suggestion I can give you is to upgrade to a newer Firebird version (2.5.4). Commented Sep 23, 2015 at 15:35
  • 1
    To expand on my previous comment, it looks like the server process (which for Classic is per connection) crashes. This might be related to using UDFs with bugs, but it might also be caused by bugs in Firebird itself. Since 2.0.7 there have been quite a number of Firebird releases with bug fixes for server crashes. You might also want to check the firebird.log of the server. Commented Sep 25, 2015 at 7:01

3 Answers 3

7

We were able to reproduce the issue for Firebird 2.1.3.18185 by killing the Firebird task via the Task-Manager during executing a query via ADO.NET data provider (version 4.7.0). After that, we were always receiving the following exception:

System.Data.Entity.Core.EntityCommandExecutionException: An error occurred 
while executing the command definition. See the inner exception for details. 
    ---> FirebirdSql.Data.FirebirdClient.FbException: Error reading data from 
    the connection.
    ---> FirebirdSql.Data.Common.IscException: Error reading 
    data from the connection. at 
    FirebirdSql.Data.Client.Managed.Version10.GdsTransaction.BeginTransaction(Transa
    ctionParameterBuffer tpb) in c: Users Jiri Documents devel NETProvider 
    working NETProvider src FirebirdSql.Data.FirebirdClient Client Managed 
    Version10 GdsTransaction.cs:line 162 at 
    FirebirdSql.Data.Client.Managed.Version10.GdsDatabase.BeginTransaction(Transacti
    onParameterBuffer tpb) in c: Users Jiri Documents devel NETProvider working 
    NETProvider src FirebirdSql.Data.FirebirdClient Client Managed Version10 
    GdsDatabase.cs:line 571 at 
    FirebirdSql.Data.FirebirdClient.FbTransaction.BeginTransaction() in c: Users 
    Jiri Documents devel NETProvider working NETProvider src 
    FirebirdSql.Data.FirebirdClient FirebirdClient FbTransaction.cs:line 363 
— End of inner exception stack trace —

In our case, the problem was solved and verified by disabling connection pooling (connection-string: '...;Pooling=false'). Interesting for us was the fact that according to [1] this is expected behavior when using connection pooling where the connection has been disconnected between several requests.

I hope this answer will help somebody else. This solution is also working with current ADO.NET 5.0.5 in our case.

Best regards, Thomas

[1] http://tracker.firebirdsql.org/browse/DNET-585?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel

3
  • Disabling connection pooling (connection-string: '...;Pooling=false') Did the TRICK . Thank you :) Commented Nov 14, 2016 at 10:06
  • 1
    I ran into this problem too. It is sad that there is no fix for that after that we are in version 5.12 of the ADO.net component!!
    – Franki1986
    Commented Mar 14, 2018 at 8:29
  • Warning: depends on architecture of application but disabling pooling is not good option for every application because every time when you are opening the new connection it takes significant amount of time. The better solution is to set connection.ConnectionLifeTime = 60 seconds (or so) and let the pool manager manage old connections. Commented Apr 5, 2018 at 8:58
1

I just got this error. I have a program working with Firebird 2.5.9 written using Delphi 10.3 and Fibplus 7.6. Recently I migrated this program to Lazarus using IBX library. Now I just returned from absence live and found that Delphi program after connect to Firebird database refuses to open any datasets returning subject error, but Lazarus program works fine. But within office network with backup server on one of workstations both programs work fine. Thank you for the tip, I'l try to change configuration parameters.

1
0

I get this error when execute query that length > max query length

in FireBird 4.x i get Error reading data from the connection after update to 6.6 i get new error "335544721 : Unable to complete network request to host..."

it was fixed by split query to some less query

(default 8191 characters when using UTF-8)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.