Jump to content

.net Db Transaction Help


Recommended Posts

Posted

Bhayya, I wrote a method that will be doing this 

 

private void method1(List<object>updates)

{

    using (var context = DbFactory.Initialize<DBEntities>())
            {
                using (DbTransaction tx = context.BeginTransaction())
                {
                    //Perform some inserts
                    context.GuardSaveChanges();
                    tx.Commit();
                }
            }
 
    using (var context = DbFactory.Initialize<DBEntities>())
            {
                using (DbTransaction tx = context.BeginTransaction())
                {
                    //Perform some updates
                    context.GuardSaveChanges();
                    tx.Commit();
                }
            }

}

Posted

Reviwe cheyyamani team ki email chesa,

okadu said this: if first transaction throws an error will id try to go to the second step and do the second transaction ?

if yes then we will get 2 errors kada annadu 

 

is there a better way to code this ?

the reason for 2 transactions is:

first transaction lo oka insert chestunnam, we are passing that value to a different service in the second transaction 

first di commit avvakapote the service is throwing an error (cant fetch value from DB ani)

Posted

first daantlo error vasthe second daaniki velladu. it crashes. 

Have Try catch blocks

Posted

first daantlo error vasthe second daaniki velladu. it crashes.
Have Try catch blocks

Using is translated as try catch and will call dispose if an exception occurs.. Exception record cheyyali inkemaina cheyyali ante use try catch finally...
Posted

Using is translated as try catch and will call dispose if an exception occurs.. Exception record cheyyali inkemaina cheyyali ante use try catch finally...

Bhayya, here is the code. Is this what you wanted me to do ??

nenu first paste chesina code is called from this originalmethod 

public void originalmethod(updates)

{

try

{

     method1(updates)

}

catch (Exception ex)

            {
ExceptionPolicy.HandleException(ex, "Legacy Exception Policy");
                ServiceLogger.LogError(OpName, ex);
            }
            finally
            {
                LegacyExceptionHelper.ClearExternalServiceRequestsAndResponsesFromThreadContext();
            }

}

Posted

Bhayya, here is the code. Is this what you wanted me to do ??
nenu first paste chesina code is called from this originalmethod
public void originalmethod(updates)
{
try
{
method1(updates)
}
catch (Exception ex)
{

ExceptionPolicy.HandleException(ex, "Legacy Exception Policy");
ServiceLogger.LogError(OpName, ex);
}
finally
{
LegacyExceptionHelper.ClearExternalServiceRequestsAndResponsesFromThreadContext();
}
}

Method lo using lopala try catch pettu rather than wrapping the method inside try catch..
Posted

Method lo using lopala try catch pettu rather than wrapping the method inside try catch..

Agreed

Posted

Agreed

first using lo oka try catch and second using lo oka try catch pettala ?

Posted

first using lo oka try catch and second using lo oka try catch pettala ?

2 using loo pettali, rendu commit lu vaduthunnav kabatti

×
×
  • Create New...