我们正致力于将来自不同源系统(Firebird,Oracle,SQL Server)的数据迁移到一个目标系统(SQL Server)。
我们从Firebird连接中读取连接异常中的数据时出现错误。
我们正在使用的代码
用于创建SourceSystem对象的静态DbFactory类
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();
}
}
从DbManager继承的FireBirdDbManager类
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云服务
答案 0 :(得分:6)
我们能够在通过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 :(得分:0)
当执行查询长度> 最大查询长度
时,出现此错误 在FireBird 4.x中,我从连接读取数据时出错 更新到6.6后,我收到新错误“ 335544721 :无法完成对主机的网络请求...”
它已通过拆分查询固定为较少的查询
(使用UTF-8时默认为8191个字符)