从连接 Firebird 读取数据时出错

Error reading data from the connection Firebird

我们正在努力将数据从不同的源系统(Firebird、Oracle、SQL 服务器)迁移到一个目标系统(SQL 服务器)。

我们收到来自 Firebird 连接的从连接读取数据时出错异常。

我们正在使用的代码

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;
            }
        }
    }
}

异常图片

运行迁移 3 到 4 次后出现异常。如果我再次重新启动服务,我们可以 运行 3 到 4 次迁移。

我们用来调用各个源系统的代码:

我们是Firebird数据库系统的新手,无法解决问题。在旁注中,我们使用的是 Visual Studio 2012,Azure 云服务

在通过 ADO.NET 数据提供程序(版本 4.7.0)执行查询期间,通过任务管理器终止 Firebird 任务,我们能够重现 Firebird 2.1.3.18185 的问题。在那之后,我们总是收到以下异常:

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 —

在我们的案例中,问题已通过禁用连接池 (connection-string: '...;Pooling=false') 得到解决和验证。对我们来说有趣的是,根据 [1],这是使用连接池时的预期行为,其中连接已在多个请求之间断开。

我希望这个回答能对其他人有所帮助。在我们的案例中,此解决方案也适用于当前的 ADO.NET 5.0.5。

此致, 托马斯

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

当执行长度 > 最大查询长度

的查询时出现此错误

在 FireBird 4.x 我从连接读取数据时出错 更新到 6.6 后我收到新错误“335544721:无法完成对主机的网络请求...”

它已通过拆分查询修复为一些较少的查询

(使用 UTF-8 时默认 8191 个字符)