Repository navigation
Closed
Labels
Description
I'm using Npgsql 3.0.3 and a PostgreSQL server 9.3 and I'm trying to use a distributed transaction to orchestrate some data movement between two different database servers.
The code I'm using the the following:
using (var sourceDbConnection = new NpgsqlConnection(SourceConnectionString))
using (var destinationDbConnection = new NpgsqlConnection(DestinationConnectionString))
using (var scope = new TransactionScope())
{
sourceDbConnection.Open();
destinationDbConnection.Open();
Logger.Info("Moving data for the {0} table.", TableName.ToUpper());
var innerStopWatch = new Stopwatch();
innerStopWatch.Start();
foreach (var entity in entities)
{
var etlEntity = new EtlInfoItem
{
MigratedEntityId = category.RowId,
ProjectId = category.ProjectId,
ExecutionDatetime = DateTime.Now
};
// Insert into the destination database
var isRowMigrated = InsertEntity(entity, DestinationSchema, destinationDbConnection);
if (isRowMigrated)
{
// Update the ETL migration table
InsertCompletedEtlMigrationEntity(etlEntity, EtlSchema, sourceDbConnection);
}
else
{
// Update the ETL migration table
InsertFailedEtlMigrationEntity(etlEntity, EtlSchema, sourceDbConnection);
}
}
Logger.Info("Data moved in {0} sec.", innerStopWatch.Elapsed);
Logger.Info("Committing transaction to the source database");
innerStopWatch.Restart();
scope.Complete();
innerStopWatch.Stop();
Logger.Info("Transaction committed in {0} sec.", innerStopWatch.Elapsed);
}
When the TransactionScope exits from the scope (when exiting the using statement), I get a Null Reference Exception with the following stack trace:
Server stack trace:
at Npgsql.NpgsqlConnector.Cleanup()
at Npgsql.NpgsqlConnector.Break()
at Npgsql.NpgsqlConnector.ReadSingleMessage(DataRowLoadingMode dataRowLoadingMode, Boolean returnNullForAsyncMessage)
at Npgsql.NpgsqlConnector.ReadExpectingT
.........
It happens randomly.
Activity
roji commentedon Nov 17, 2015
@damageboy, want this?
roji commentedon Nov 17, 2015
SO link: http://stackoverflow.com/questions/33588232/does-npgsql-provider-has-support-for-transactionscope/33592757
roji commentedon Dec 14, 2015
@damageboy do you want to take a look at this?
roji commentedon May 4, 2016
I'm really sorry this hasn't received an answer sooner. I'm hard at work preparing 3.1 for a beta release and won't be able to look at this soon. However, one of 3.2's major goals is a cleanup of how distributed transactions work, and this will be definitely be taken care of.
roji commentedon Dec 11, 2016
Am finally getting around to work on System.Transactions support - am pretty much rewriting the whole thing to be safer and simpler. A lot has changed regardless in Npgsql since this issue was opened, so I'm going to close it. If you can help test the upcoming 3.2, you should be able to grab recent 3.2 CI nugets from the unstable feed, or you can wait until a beta is released (hopefully not too long from now).
If you encounter the same issue with these new versions, please post back here and I'll reopen.