Connection must be opened on rollback and accent error

Connection must be opened on rollback and accent error

Postby concware » Thu 09 Jan 2014 23:08

Hello,

I am starting to use the newest version of dotConnect for PostgreSql.
The environment is MVC 5 and Entity Framework 5.

My main problem is with the accents, if I get an entity, which fields contain accents, it returns the following string field:
"Teljesjogú Adminisztrátor"

Instead of this:
"Teljesjogú Adminisztrátor"

On the other hand if i insert a new row in postgresql with accents, there is no error. If I try to save an entity, which fields has accents like 'éáűőúöüó' with dotconnect, throws the following exception:

System.Data.Entity.Infrastructure.DbUpdateException occurred

InnerException: Devart.Data.PostgreSql.PgSqlException
HResult=-2147467259
Message=invalid byte sequence for encoding "UTF8": 0xe1 0x72 0x6f
Source=Devart.Data.PostgreSql
ErrorCode=-2147467259
CallStack=""
ColumnName=""
ConstraintName=""
DataTypeName=""
DetailMessage=""
ErrorSql=INSERT INTO "User"("Alias", "LastName", "FirstName", "Password", "PasswordValidTo", "DateOfBirth", "Email", "ZIPCode", "City", "Address", "DepartmentID", "State", "Created", "CreatedBy", "Modified", "ModifiedBy")
VALUES ($1, $2, $3, $4, NULL, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
RETURNING "ID"
FileName=src\backend\utils\mb\wchar.c
Hint=""
InternalPosition=""
InternalQuery=""
LineNumber=2020
Position=0
ProcedureName=report_invalid_encoding
SchemaName=""
TableName=""
StackTrace:
at Devart.Data.PostgreSql.PgSqlDataReader.f(Int32 A_0)
at Devart.Data.PostgreSql.PgSqlCommand.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords)
at Devart.Common.DbCommandBase.InternalExecute(CommandBehavior behavior, IDisposable stmt, Int32 startRecord, Int32 maxRecords, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior, Boolean nonQuery)
at Devart.Common.DbCommandBase.ExecuteDbDataReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at Devart.Data.PostgreSql.Entity.d.a(CommandBehavior A_0)
at Devart.Common.Entity.i.b(CommandBehavior A_0)
at Devart.Data.PostgreSql.Entity.d.b(CommandBehavior A_0)
at System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Mapping.Update.Internal.DynamicUpdateCommand.Execute(UpdateTranslator translator, EntityConnection connection, Dictionary`2 identifierValues, List`1 generatedValues)
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)

My second problem is that I am using a custom Transaction partial class, that is part of my DbContextEntities instance (System.Data.Entity.DbContext). It contains an own transaction handling with the following code:

Code: Select all

private int _numberOfTransactions = 0;
private DbTransaction _transaction = null;

public DbTransaction Transaction
{
    get
    {
        return _transaction;
    }
}

public DbTransaction BeginTransaction()
{
    return BeginTransaction(IsolationLevel.ReadCommitted);
}

public DbTransaction BeginTransaction(System.Data.IsolationLevel isolation)
{
    if (this.Database.Connection.State == ConnectionState.Closed)
        this.Database.Connection.Open();

    if (_transaction == null)
    {
        _transaction = this.Database.Connection.BeginTransaction(isolation);
        _numberOfTransactions = 1;
    }
    else
    {
        ++_numberOfTransactions;
    }

    return _transaction;
}

public void CommitTransaction()
{
    SaveChanges();

    if (_transaction != null && _numberOfTransactions == 1)
    {
        _transaction.Commit();
        _transaction.Dispose();
        _transaction = null;
        _numberOfTransactions = 0;
    }
    else if (_numberOfTransactions > 0)
    {
        --_numberOfTransactions;
    }
}

public void RollbackTransaction()
{
    if (_transaction != null && _transaction.Connection != null && _numberOfTransactions == 1)
    {
        _transaction.Rollback();
        _transaction.Dispose();
        _transaction = null;
        _numberOfTransactions = 0;
    }
    else if (_numberOfTransactions > 0)
    {
        --_numberOfTransactions;
    }
}



I use this transaction handling in other projects with any problems, but in this environment, i noticed that if the Data Access Layer or business logic layer starts a transaction with this code with BeginTransaction() method and after the first SaveChanges() method, the database connection will be closed. (DbContext.DataBase.Connection) This is a big problem, because if I try to rollback with the RollBackTransaction() method, because an error occured while a long deleting or saving business logic, it throws the following exception:

System.InvalidOperationException occurred
HResult=-2146233079
Message=Connection must be opened.
Source=Devart.Data
StackTrace:
at Devart.Common.Utils.CheckConnectionOpen(IDbConnection connection)
at Devart.Data.PostgreSql.PgSqlTransaction.Rollback()
at ...

I would like to thanks for all of your assistance in advance.
concware
 
Posts: 14
Joined: Thu 09 Jan 2014 21:51

Re: Connection must be opened on rollback and accent error

Postby concware » Fri 10 Jan 2014 09:35

I solved the Hungarian accent problem with the following url:
http://forums.devart.com/viewtopic.php?t=15299

I did not find solution for the transaction handling, yet.
concware
 
Posts: 14
Joined: Thu 09 Jan 2014 21:51

Re: Connection must be opened on rollback and accent error

Postby Shalex » Fri 10 Jan 2014 10:01

concware wrote:I did not find solution for the transaction handling, yet.

Starting from the 7.1.45 build of dotConnect for PostgreSQL, the behaviour is changed: now a transaction rollbacks on Connection.Close() if Transaction.Commit() was not called before closing the connection (revision history). We recommend using the latest (7.2.65) build. Please upgrade and notify us about the result.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Connection must be opened on rollback and accent error

Postby quooston » Mon 20 Jan 2014 02:17

Does that mean that a transaction started using TransactionScope will only roll back when you close the connection?

That does not sound like desired behaviour to me. When all transaction scopes are executed and there is no final call to .Complete(), then the transaction should be rolled back.

I have a number of integration tests which are now failing (after a v7 upgrade) due to transactions in a transaction scope not being rolled back.
quooston
 
Posts: 5
Joined: Tue 05 Mar 2013 00:19

Re: Connection must be opened on rollback and accent error

Postby Shalex » Mon 20 Jan 2014 17:56

Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Connection must be opened on rollback and accent error

Postby concware » Sun 09 Feb 2014 13:37

I have installed the newest build of dotconnect, by my main problem is still occured.

At the beginning of post in the code snippet i use a DbTransaction property and Begin, Commit and RollBack Transaction methods. After I call BeginTransaction and CommitTransaction methods, if I call the RollBackTransaction method, exception throwed with the following message:

System.InvalidOperationException occurred
HResult=-2146233079
Message=Connection must be opened.
Source=Devart.Data
StackTrace:
at Devart.Common.Utils.CheckConnectionOpen(IDbConnection connection)
at Devart.Data.PostgreSql.PgSqlTransaction.Rollback()
at ...

I use this transaction handling in lot of projects without any problem to test business logic layer by unit tests. I can not run unit tests because the RollBack throwed the exception above.

Please, use my transaction handling code snippet to reproduce the bug.
concware
 
Posts: 14
Joined: Thu 09 Jan 2014 21:51

Re: Connection must be opened on rollback and accent error

Postby Shalex » Mon 10 Feb 2014 14:54

Please run your program in the debug mode, set a break point in the code, navigate to Visual Studio > Debug > Windows > Modules and make sure that the Devart.* assemblies from the latest (7.5.179) version of dotConnect for PostgreSQL are loaded in the process of your application:
Devart.Data.dll v 5.0.638.0
Devart.Data.PostgreSql.dll v 7.2.90.0
Devart.Data.PostgreSql.Entity.dll v 7.2.90.0

If this doesn't help, send us a complete small test project with the corresponding DDL/DML script for reproducing.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Connection must be opened on rollback and accent error

Postby concware » Thu 13 Feb 2014 23:15

I did not understand, why did you think that i can not reinstall the new version of dotconnect for postgreSQL. I have checked the version numbers of postgre Devart dll assemblies. These are the followings:
- Devart.Data.PostgreSql.dll 7.2.90.0
- Devart.Data.dll 5.0.882.0

I have created a sample test project by the name of TransactionHandling. I have cleaned the solution, so there is no dll references. I use the Entity Framework 5 and Unit Test Project.
You can download it by the following url:
http://we.tl/lX0QQqKk3h

The problem is not the transaction handling, after I added a new entity and called SaveChanges method the connection of database is closed. If i am right, this build is unusable because we can not call SaveChanges more than once, that is unacceptable in a complex business logic saving.

I am looking forward to your early reply.
concware
 
Posts: 14
Joined: Thu 09 Jan 2014 21:51

Re: Connection must be opened on rollback and accent error

Postby Shalex » Mon 17 Feb 2014 16:49

concware wrote:Message=Connection must be opened.
Source=Devart.Data
StackTrace:
at Devart.Common.Utils.CheckConnectionOpen(IDbConnection connection)
at Devart.Data.PostgreSql.PgSqlTransaction.Rollback()

We have reproduced the error with your project and are investigating the issue.

concware wrote:I have a number of integration tests which are now failing (after a v7 upgrade) due to transactions in a transaction scope not being rolled back.

Did your previous version of dotConnect for PostgreSQL work without error in the same scenario? Please specify its exact build number (x.xx.xxx).
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Connection must be opened on rollback and accent error

Postby concware » Mon 17 Feb 2014 18:45

Unfortunatelly, I cannot specify a build number, because this tests based on MSSQL and not on Postgre SQL.
concware
 
Posts: 14
Joined: Thu 09 Jan 2014 21:51

Re: Connection must be opened on rollback and accent error

Postby concware » Fri 28 Feb 2014 09:59

When can i expect the new build, that fix the connection problem?

My project requires this bugfixes, because i cannot run unit tests and cannot save complex entities in transaction and i think i am not alone by this problem.
concware
 
Posts: 14
Joined: Thu 09 Jan 2014 21:51

Re: Connection must be opened on rollback and accent error

Postby Shalex » Tue 04 Mar 2014 13:13

We have implemented the following changes:
  • The behaviour is changed: if PgSqlTransaction has been already assigned to the PgSqlConnection object, all subsequent calls of the BeginTransaction method on the same PgSqlConnection object will return an existing PgSqlTransaction instance
  • The message of the exception, when an attempt to rollback a closed transaction is made, is improved ("This PgSqlTransaction has completed; it is no longer usable.")
We are planning to release the corresponding public build of dotConnect for PostgreSQL this week.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Connection must be opened on rollback and accent error

Postby Shalex » Fri 07 Mar 2014 07:38

New version of dotConnect for PostgreSQL 7.3 is released!
It can be downloaded from http://www.devart.com/dotconnect/postgresql/download.html (trial version) or from Registered Users' Area (for users with active subscription only).
For more information, please refer to http://forums.devart.com/viewtopic.php?f=3&t=29099.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Re: Connection must be opened on rollback and accent error

Postby concware » Thu 24 Jul 2014 20:17

I have downloaded the latest version of dotConnect for PostgreSQL 7.3.201 (10-Jul-2014).
I checked the transaction problem and it is occured again! I have got the following exception when calling commit method:
This PgSqlTransaction has completed; it is no longer usable.

Please, check it with the following example programs as soon as possible you can!
http://we.tl/lX0QQqKk3h
concware
 
Posts: 14
Joined: Thu 09 Jan 2014 21:51

Re: Connection must be opened on rollback and accent error

Postby Shalex » Mon 28 Jul 2014 13:21

concware wrote:I have got the following exception when calling commit method:
This PgSqlTransaction has completed; it is no longer usable.

Please make sure that there is no attempt to rollback a closed transaction in your code.

concware wrote:Please, check it with the following example programs as soon as possible you can!
http://we.tl/lX0QQqKk3h

The download isn't available anymore. Please upload your project again, and we will process your request as soon as possible.
Shalex
Devart Team
 
Posts: 7774
Joined: Thu 14 Aug 2008 12:44

Next

Return to dotConnect for PostgreSQL