Question : Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction

Stack Trace:
   at MyApplication.Frame.Data.DatabaseHelper.ExecuteScalar(ExecutingEnvironment execEnvironment, Database database, Object[] values)
  at MyApplication.Frame.Data.DatabaseHelper.ExecuteScalar(ExecutingEnvironment execEnvironment, ConnectionString connection, Object[] values)
  at MyApplication.Frame.Security.DbPermission.UserHasPermissions(Int32 userKey)
  at MyApplication.Frame.Security.PermissionManager.UserHasPermissions(Int32 userKey)
  at MyApplication.Frame.Security.Authentication.UserHasPermissions(Int32 userKey, IIdentity localIdentity)
  at MyApplication.Frame.Security.Authentication.Login(ApplicationEntranceInfo entrance, String source, String userName, String password, String sessionID, IPrincipal& currentPrincipal)

Inner Exception
---------------
Exception information:
Exception type: SqlException
Exception message: Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.

Stack Trace:
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
  at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
  at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
  at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
  at System.Data.SqlClient.SqlDataReader.ConsumeMetaData()
  at System.Data.SqlClient.SqlDataReader.get_MetaData()
  at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
  at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
  at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
  at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
  at System.Data.SqlClient.SqlCommand.ExecuteScalar()
  at Microsoft.Practices.EnterpriseLibrary.Data.Database.DoExecuteScalar(DbCommand command)
  at Microsoft.Practices.EnterpriseLibrary.Data.Database.ExecuteScalar(DbCommand command)
  at MyApplication.Frame.Data.DatabaseHelper.ExecuteScalar(ExecutingEnvironment execEnvironment, Database database, Object[] values)

the function UserHasPermissions do this simple query:
          select count(PermissionKey)
          from Permission
          where RoleKey in(select RoleKey
                           from UserRole
                           where ApplicationUserKey = @userKey)

Answer : Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction

This erro due a constraint failure on DB front; but has to do nothing with DTC. The fail rolls back the transaction and there by forces the connection instance to come out of transaction. thus the resultant error message!!
Check for other error messages logged / part of the exception for more information.
Random Solutions  
 
programming4us programming4us