Is there a way to access the full SQL query, including the values, inside my code?
I am able to log SQL queries using log4net:
<logger name="NHibernate.SQL" additivity="false">
<level value="ALL"/>
<appender-ref ref="NHibernateSQLFileLog"/>
</logger>
However, I would like to find a way to log SQL queries from the code also. This way I will log the specific SQL query that causes an exception in my try/catch statement.
Right now I have to data-mine the SQLFileLog to find the query that caused the exception when an exception occurs and it is not efficient.
Either use sql profiler or have a look at nhprof at http://nhprof.com/
Both will let you see sql output.
Also set the show_sql property in hibernate config file
You can override driver:
And then use it in configuration:
you can use an interceptor to do this:
See Nhibernate Docs for the different ways to register it with nhibernate.
Use a log4net appender with specific target (afair it supports being toggled on/off) or just extend it and toggle it within your try-catch-finally-off.