What does the [Rollback] attribute do? Does it set up a session and a transaction? If so you're doing one transaction inside of another...
On Mon, Apr 6, 2009 at 7:23 AM, joshlrogers <[email protected]> wrote: > > I am running a test: > > [Test] > [Rollback] > public void CanDeleteRatingGroupByName() > { > > CWTRatingGroup newGroup = new CWTRatingGroup(); > newGroup.Name = "Delete Me"; > newGroup.UserAdded = provider.GetUserById(1); > > int id = provider.AddCWTRatingGroup(newGroup); > > provider.RemoveCWTRatingGroupByName(newGroup.Name); > > Assert.IsNull(provider.GetCWTRatingGroupById(id)); > } > > The line > > int id = provider.AddCWTRatingGroup(newGroup); > > fails with the following exception: > > NHibernate.TransactionException: Begin failed with SQL exception ---> > System.Data.SqlClient.SqlException: Distributed transaction completed. > Either enlist this session in a new transaction or the NULL > transaction. > 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.TdsParser.TdsExecuteTransactionManagerRequest > (Byte[] buffer, TransactionManagerRequestType request, String > transactionName, TransactionManagerIsolationLevel isoLevel, Int32 > timeout, SqlInternalTransaction transaction, TdsParserStateObject > stateObj, Boolean isDelegateControlRequest) > at > System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon > (TransactionRequest transactionRequest, String transactionName, > IsolationLevel iso, SqlInternalTransaction internalTransaction, > Boolean isDelegateControlRequest) > at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction > (TransactionRequest transactionRequest, String name, IsolationLevel > iso, SqlInternalTransaction internalTransaction, Boolean > isDelegateControlRequest) > at System.Data.SqlClient.SqlInternalConnection.BeginSqlTransaction > (IsolationLevel iso, String transactionName) > at System.Data.SqlClient.SqlInternalConnection.BeginTransaction > (IsolationLevel iso) > at System.Data.SqlClient.SqlConnection.BeginDbTransaction > (IsolationLevel isolationLevel) > at > System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction > () > at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel > isolationLevel) > --- End of inner exception stack trace --- > at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel > isolationLevel) > at NHibernate.Transaction.AdoTransaction.Begin() > at TEAMSData.DataLayer.NHibernateDataProvider.AddCWTRatingGroup > (CWTRatingGroup ratingGroup) in C:\Source\TEAMS\TEAMS\TEAMSData > \DataLayer\NHibernateDataProvider.cs:line 62 > at > TEAMSDataUnitTests.CWTRatingGroupDeleteTests.CanDeleteRatingGroupByName > () in C:\Source\TEAMS\TEAMS\TEAMSUnitTests\CWTRatingGroupTests.cs:line > 164 > > What confuses me is that the function that this calls is called in > other tests successfully. Here is that code just for clarity sake: > > public int AddCWTRatingGroup(CWTRatingGroup ratingGroup) > { > > try > { > ratingGroup.DateAdded = DateTime.Now; > > session.Transaction.Begin(); > > int id = (int)session.Save(ratingGroup); > session.Flush(); > > session.Transaction.Commit(); > > return id; > } > catch (Exception) > { > if( session.Transaction.IsActive ) > session.Transaction.Rollback(); > > ResetSession(); > throw; > } > > } > > Session.Transaction.Begin() is what actually throws the exception in > this case. However I am doing almost the exact same thing in another > test and it runs just fine. > > Any ideas? > > Thanks again, > Josh > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
