Question

I'm working on a web application that uses NHibernate. Sometimes when there is a bug in the SQL generated by NHibernate, the error I get is extremely unhelpful:

NHibernate.Exceptions.GenericADOException: could not execute batch command.[SQL: SQL not available] ---> System.Data.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.

The code that threw the error generated dozens and dozens of SQL statements, which are stored in a log, such as:

INSERT 
INTO
    ShipOrder (ShipContactName, ShipAddress1, ShipAddress2, ShipAddress3, ShipCity, ShipStateCode, ShipPostalCode, ShipCountryCode, ShipProvider) 
VALUES
    ('Tobias Funke', '12345 Anywhere Pl', NULL, NULL, 'Anytown', 'AA', '12345', 'US', 'UPS GROUND')

I want to try running this query to see if it is the cause of the error. Is there a way I can simulate the insert in SQL Server Management Studio so I don't create dummy data?

Was it helpful?

Solution

Wrap it in a transaction, and rollback instead of commit:

BEGIN TRANSACTION
INSERT 
INTO
    ShipOrder (ShipContactName, ShipAddress1, ShipAddress2, ShipAddress3, ShipCity, ShipStateCode, ShipPostalCode, ShipCountryCode, ShipProvider) 
VALUES
    ('Tobias Funke', '12345 Anywhere Pl', NULL, NULL, 'Anytown', 'AA', '12345', 'US', 'UPS GROUND')
ROLLBACK TRANSACTION
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top