Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8870717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:48:21+00:00 2026-06-14T17:48:21+00:00

I have a WCF MSMQ service (hosted in a windows service). My method has

  • 0

I have a WCF MSMQ service (hosted in a windows service). My method has the TransactionScopeRequired attribute on it.

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

I was using the following approach (using the castle facility) in my data access

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

 // do work
transaction.Commit()

}

But when my main service method exits I am getting an error because I have already disposed of the Nhibernate session and I think the DTC needs this to do its commit.

My question is:

What would be the best way to close the Nhibernate session – after the DTC has committed (i.e after i have exited my service method?).

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:48:23+00:00Added an answer on June 14, 2026 at 5:48 pm

    If you wrap your code in the following

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

    Then NHibernate will not enlist in the ambient transaction and therefore DTC will not have a dependency on the database transaction.

    This is a hunch as you haven’t supplied the error details in your question.

    EDIT

    Of course by following this advice your database commit will not be performed under the same transaction as the dequeue action so if there is a failure in your database this may or may not cause the dequeue transaction to roll the message being processed back onto the queue, so you risk dropping messages in this way. You can compensate for this in various ways or you can just run the risk if the cost of dropped messages are not high.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WCF Service Using MSMQ hosted on IIS. I want to create
I have a WCF service that accesses a SQL database to fetch data .
I have a WCF service hosted as a Windows service. The WCF service uses
I have a WCF based web service hosted in windows sever 2003 machine. The
I have a WCF service hosted in a Windows service that I set to
I have a WCF Windows Service that checks for MSMQ messages. It picks the
I have successfully implemented a standard WCF service bound to MSMQ using the net.msmq
I have a WCF activated WorkFlow Service (XAMLX) setup (hosted using WorkflowServiceHost). This WCF
I have a WCF service hosted in a Windows Service. I want a website
I have self-hosted WCF service in console with netNamedPipeBinding binding. The service has just

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.