我正在使用一个使用NHibernate的Web应用程序。有时当NHibernate生成的SQL出现错误时,我得到的错误非常无益:
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.
抛出错误的代码生成了数十个SQL语句,这些语句存储在日志中,例如:
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')
我想尝试运行此查询以查看它是否是错误的原因。有没有办法在SQL Server Management Studio中模拟插入,所以我不创建虚拟数据?
答案 0 :(得分:9)
用transaction和rollback代替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