tags:

views:

84

answers:

2

I am trying to create a type of recorded data transaction that I can replay on a different database.

For example I am capturing an order into a system, when I save that I want to be able to "export" a sql script that I can run on another database to create the same order.

I am using NHibernate and I am trying to catch the sql query string for the save operation to save to a file, but with no success.

A: 

Try running a DB profiler, you'll be 100% sure about the queries being sent to DB. In case of MS SQL Server more info is here. Also you can try Nhibernate profiler.

Al Bundy
+1  A: 

Checkout this question: http://stackoverflow.com/questions/1264132/get-executed-sql-from-nhibernate

I'm not sure if there is a better alternative like an event listener, if not, the IInterceptor approach seems to be the best.

Ariel Popovsky
This does work but just not quite as the values is not passed into the Interceptor. I think the best way is to create a log4net appender and catch NHibernate.SQL logger's output there.
adriaanp
Not a bad idea, apparently that's how NHprof (the NH profiler) gets all the query information including parameters.BTW, you could try using NHibernate with both databases, there are some questions here and many blog posts on that subject.
Ariel Popovsky