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 4091634
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:23:30+00:00 2026-05-20T19:23:30+00:00

How to configure Fluent NHibernate to output queries to Trace or Debug instead of

  • 0

How to configure Fluent NHibernate to output queries to Trace or Debug instead of Console?
I’m using MsSqlConfiguration.MsSql2008.ShowSql() but it has no parameters and I can’t find anything on Google.

  • 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-05-20T19:23:30+00:00Added an answer on May 20, 2026 at 7:23 pm

    I can see from forum and blog posts everywhere that lots of others before me have looked for a way to get the SQL statements as they’re being prepared for execution. The answer typically is something along the lines of "you can’t", or "you shouldn’t".

    Whether I should or not, that’s what I wanted.

    After hours of searching, investigation and failed attempts, and finally I came up with this.

    Write up an interceptor:

    using NHibernate;
    using System.Diagnostics;
    
    public class SqlStatementInterceptor : EmptyInterceptor
    {
        public override NHibernate.SqlCommand.SqlString OnPrepareStatement(NHibernate.SqlCommand.SqlString sql)
        {
            Trace.WriteLine(sql.ToString());
            return sql;
        }
    }
    

    Of course, you don’t have to Trace.WriteLine() here, you could write it to a log file, or whatever else you need.

    In your connection manager, hook up your Interceptor like so:

    protected virtual void Configure(FluentConfiguration config)
    {
        config.ExposeConfiguration(x =>
                                       {
                                           x.SetInterceptor(new SqlStatementInterceptor());
                                       });
    }
    

    It’s not that complicated. From my perspective, certainly easier than trying to get all this XML pushed through Fluent to NHibernate – since Fluent abstracts the XML file away.

    Keep in mind, you can only have a single Interceptor – so you may need to integrate this feature with your existing Interceptor, if you already have one. On that note, you might want to give it a broader name – e.g. MyAppInterceptor, so as not to imply a specific purpose, because you may want to add other features to it later.

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

Sidebar

Related Questions

I've reviewed the post How to configure Fluent NHibernate with MySQL , but I'm
In the current application I'm developing I'm using Fluent NHibernate to configure NHibernate for
I have an application using Fluent NHibernate on the server side to configure the
Background Fluent NHibernate 1.1 (with a repository implementation using LINQ to NHibernate) in an
Is there a way to setup SQLite connection pooling using Fluent NHibernate configuration? E.g.
Has anyone gotten Fluent NHibernate to work with Castle ActiveRecord? I am particularly interested
I've just started using Fluent NHibernate and have run into the following problem trying
I recently asked a question about using Fluent NHibernate with .NET 4 - I
I'm using the following: Fluently.Configure() .Database(MsSqlConfiguration.MsSql2005.ConnectionString(connectionString)) .Mappings(m => m.AutoMappings.Add(AutoMap.AssemblyOf<Incident>() .Where(t => t.Namespace.StartsWith(EDA.DomainModel.POCO)))) .ExposeConfiguration(BuildSchema) .BuildSessionFactory();
how can i set the encoding when i'm configure nhibernate with fluent configuration on

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.