WCF using MSMQ DTC – close NHibernate session

I have a WCF MSMQ service (hosted in a Windows service). There is TransactionScopeRequired attribute on my method.

I am using Nhibernate to convert my The data is saved to my database. I want to make sure that every Nhibernate session is closed after each call.

I used the following method in my data access (using the castle facility)

< p>

using(var session = sessionManager.OpenSession())
using(var transaction = session.BeginTransaction())
{

// do work
transaction.Commit()

}

But when my main service method exits, I get an error because I have processed the Nhibernate session , I think DTC needs this to submit.

My question is:

What is the best way to close the Nhibernate session-after the DTC is submitted (that is, after I log out of my After the service method?).

Thank you.

If you wrap the code

using (TransactionScope sc = new TransactionScope(TransactionScopeOption.Suppress)) 
{
// code here
sc .Complete();
}

Then NHibernate will not be registered in environmental transactions, so DTC will not depend on database transactions.

This is a hunch, because You did not provide error details in the question.

Edit

Of course, by following this recommendation, your database submission will not be executed under the same transaction as the dequeue operation, so If your database fails, this may or may not cause the dequeue transaction to roll back the message being processed to the queue, so you risk The risk of discarding messages in this way. You can compensate for this in various ways, or if the cost of discarding messages is not high, you can take the risk.

I There is a WCF MSMQ service (hosted in a Windows service). There is TransactionScopeRequired attribute on my method.

I am using Nhibernate to save my data to my database. I want to make sure that Close each Nhibernate session after each call.

I used the following method in my data access (using the castle facility)

using(var session = sessionManager.OpenSession())
using(var transaction = session.BeginTransaction())
{

// do work
transaction.Commit()< br />
}

But when my main service method exits, I receive an error because I have processed the Nhibernate session, and I think DTC needs this to make a submission.

p>

My question is:

What is the best way to close the Nhibernate session-after the DTC submission (ie after I log out of my service method? ).

Thank you.

If you wrap the code below

using (TransactionScope sc = new TransactionScope(TransactionScopeOption.Suppress)) 
{
// code here
sc.Complete();
}

Then NHibernate will not be registered in environmental transactions, so DTC will not rely on database transactions.

This is a hunch because you did not provide error details in the question.

Edit

Of course, by following this recommendation, your database submission will not be executed under the same transaction as the dequeue operation, so if your database fails, this may or may not cause dequeue The transaction rolls back the message being processed to the queue, so you run the risk of discarding the message in this way. You can compensate for this in various ways, or if the cost of discarding the message is not high, you can take the risk.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4508 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.