Error with a DTC transaction...

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
ivanpfontanive
Posts: 3
Joined: Fri 04 Feb 2011 17:47
Location: Santa Maria-RS, Brasil

Error with a DTC transaction...

Post by ivanpfontanive » Fri 04 Feb 2011 18:19

I'm have a system that talk with two database and i need make operations inside a TransactionScope with this two databases.

So i found a error with this transaction :S
System.Data.UpdateException was caught
Message=An error occurred while updating the entries. See the inner exception for details.
Source=System.Data.Entity
StackTrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at Dllxxx.Atualizar(T entidade) in path xxxxxxx:line 94
InnerException: Devart.Data.MySql.MySqlException
Message=Lost connection to MySQL server during query
Source=Devart.Data.MySql
ErrorCode=-2147467259
Code=2013
SqlState=00000
StackTrace:
at Devart.Common.ai.a(Exception A_0)
at Devart.Data.MySql.bh.a(Exception A_0)
at Devart.Common.s.e(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Data.MySql.bk.a(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Data.MySql.bk.a()
at Devart.Data.MySql.bk.d()
at Devart.Data.MySql.u.a(ag[]& A_0, Int32& A_1)
at Devart.Data.MySql.u.a(Byte[] A_0, Int32 A_1, Boolean A_2)
at Devart.Data.MySql.a1.b()
at Devart.Data.MySql.a1.u()
at Devart.Data.MySql.MySqlCommand.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()
at Devart.Common.DbCommandBase.ExecuteNonQuery()
at Devart.Data.MySql.Entity.b.a.e()
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)
InnerException: System.TimeoutException
Message=Server did not respond within the specified timeout interval.
Source=Devart.Data.MySql
StackTrace:
at Devart.Common.a.b(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Common.at.c(Byte[] A_0, Int32 A_1, Int32 A_2)
at Devart.Common.s.e(Byte[] A_0, Int32 A_1, Int32 A_2)
InnerException: System.IO.IOException
Message=Unable to read data from the transport connection: Uma tentativa de conexão falhou porque o componente conectado não respondeu
corretamente após um período de tempo ou a conexão estabelecida falhou
porque o host conectado não respondeu.
Source=System
StackTrace:
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at Devart.Common.a.b(Byte[] A_0, Int32 A_1, Int32 A_2)
InnerException: System.Net.Sockets.SocketException
Message=Uma tentativa de conexão falhou porque o componente conectado não respondeu
corretamente após um período de tempo ou a conexão estabelecida falhou
porque o host conectado não respondeu
Source=System
ErrorCode=10060
NativeErrorCode=10060
StackTrace:
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
InnerException:
The error message:
Message=Unable to read data from the transport connection: Uma tentativa de conexão falhou porque o componente conectado não respondeu
corretamente após um período de tempo ou a conexão estabelecida falhou
porque o host conectado não respondeu.

The code is

Code: Select all

using (TransactionScope transaction = new TransactionScope())
                {
                    // Code for include or update the first database.
                   

                    // Code for include or update the second database.
                   

                  // Code for include or update the second database again.
                   

                   only commit the transaction if all operations was sucessfull
                    transaction.Complete();
                }
Have a solution for this or someone found the same error?

I'm using Entity Framework 4 and dotConnect for Mysql 6.10.96 trial, I', was using dotConnect for Mysql professional 5.80.152.0 but I found the same error.

Thanks!

ivanpfontanive
Posts: 3
Joined: Fri 04 Feb 2011 17:47
Location: Santa Maria-RS, Brasil

Hi, I found a solution.

Post by ivanpfontanive » Mon 07 Feb 2011 15:12

My implementation was with a method find before a insert or update, inside of same scope transaction, this maked that the table stay in state locked, and so dont was possible insert or update in the same table.
My code:

Code: Select all

using (TransactionScope transaction = new TransactionScope()) 
                { 
                  
                  // Code for find a data in table of the first database. 
                    

                    // Code for include or update the first database. 
                    

                  // Code for find a data in table of the second database. 
                    

                    // Code for include or update the second database. 
                    

                  // Code for include or update the second database again. 
                    

                   only commit the transaction if all operations was sucessfull 
                    transaction.Complete(); 
                }
Solution:

Code: Select all

// Code for find a data in table of the first database. 
     
using (TransactionScope transaction = new TransactionScope()) 
                { 
                                 
                    // Code for include or update the first database. 
                    

              using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) 
              { 
                  // Code for find a data in table of the second database. 
                    
                   transaction.complete();
               }

                    // Code for include or update the second database. 
                    

                  // Code for include or update the second database again. 
                    

                   only commit the transaction if all operations was sucessfull 
                    transaction.Complete(); 
                }
Using this option TransactionScopeOption.RequiresNew, make the new transaction for method find so this transaction finally when complete release the table for insert and update.

Thanks.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Mon 07 Feb 2011 15:22

ivanpfontanive, thank you for sharing the solution. I have deleted your duplicate post.

Post Reply