How to get the sql query from a NHibernate save - nhibernate

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.

Checkout this question: 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.

Related

Write non-SQL dataset to SQL table in DataIku

I dont seem to find a way to write the output from a previous step in the flow into a SQL table, using the SQL recipes. When I read the documentation, it seems both types of SQL action can only take as an input a SQL dataset? This cant be write, as you would imagine you would want to create datasets in the flow and then commit them to a database?
https://doc.dataiku.com/dss/latest/code_recipes/sql.html
In the docs above, it describes In\Out parameters as needing to be SQL.
Indeed, it doesn't seem possible with a SQL recipe which executes fully in the database.
That being said you can probably use a sync recipe to put your non-SQL dataset in your SQL db so that you can execute a SQL recipe.

How to save a query in SQL Server using a trigger?

How to save a query in SQL Server using a trigger?
I have a database that supplies different applications. I have detected that one of them is updating a column to null. I want to save the query that does it, so I can know which application is having this error.
Is there a way to save the query that executes a trigger?

"Select data source" popping-up when executing a SQL writed query

I try to create a pretty complex database on ms Access 2013, so I wanted to type it directly in SQL. It has no errors, as other DBMS can fully build the database from the script I wrote (for example, phpmyadmin imports it with no difficulty).
On this tutorial, it is showed how to write a SQL query in order to build tables. I thought this way matched well with my goal as I could copy-paste my script in the query and run it to create the whole thing.
But when I tried to open/double-click on the query a pop-up appears saying "Select data source", waiting for me to select an ODBC, either from a file or a host, before continuing and executing the query.
I tried other types of queries (creating only one table at time, trying on a blank file, or even SELECT * FROM *), bt this message keeps showing up and I really don't know how to deal with it as I don't want to connect to anything but the infile database.
Does anyone got a hint about what to do in this case?
Or, even better, how could Access import my SQL script in order to create the database?
You should configure the database connection in the ODBC and check whether the connection is established or not. Once the connection is established, you can run the query to fetch the data or create tables as per your requirement.

Modify statement prior execution

I use an application connected with an sql database. I found using the profiler that the application runs an update query with a syntax error. I don't have access to the application's source code. The result is that the record is not updated. Is there a way to modify the query every time it is executed with something like trigger? I can't use INSTEAD OF because there ism't any record updated or inserted.
This answer
https://stackoverflow.com/a/3319031/1359088
suggests a way to log to a text file all the errors. You could write a little utility and schedule it to run every hour or whatever, which could read through this log, find the erroneous sql statements, fix them, then run them itself.

Plain SQL output from NHibernate

I need:
Plain SQL that I can run without modification with sqlcmd.exe to insert testdata into testdatabase.
I have:
Service calls and entities to generate the insert operations with NHibernate.
Not working solution:
Log output to text-file. NHibernate generates parameterized sql but logs them in a format not runnable by sqlcmd.exe.
Is there any way to force NHibernate to generate sql without parameters?
Or is there any better solutions to the problem?
depending on your schema, it may be easier to just generate INSERTs from the actual database, try using a utility like:
Procedure to script your data (to generate INSERT statements from the existing data)
You could record a transaction log, the SQL Server Profiler is providing something like this.
In our application, we wrote factories in C# which generate the entities. We don't have SQL scripts to create testdata. An executer (.exe) picks up assemblies, creates the entities and stores them to the db. This way we don't have to maintain scripts. The factories are compile-time-safe.