I'm trying to make my integration tests more idempotent. One idea was to execute rollback after every test, the other idea was to some how programatically parse the text, similar to the green check box in Query Analyzer or SSMS.
How do I get SQL Server to parse my command without running it using ADO.NET?
UPDATE:
This is what finally worked as desired:
using (DbCommand executeOnly = Factory.DbCommand())
{
executeOnly.Connection = command.Connection;
executeOnly.CommandType = CommandType.Text;
executeOnly.CommandText = "SET NOEXEC ON;" + sqlCommand;
executeOnly.Connection.Open();
executeOnly.ExecuteNonQuery();
}
//set more properties of command.
command.Execute();
For inexplicable reasons, "SET PARSEONLY ON
" only worked in Query Analyzer. I couldn't set this on an ADO.NET connection. It is just as well because PARSEONLY
seems to catch only syntax errors, which isn't a common error. SET NOEXEC ON
will catch a wider varieties of errors, such as a view that references a missing table or column or a missing parameter in a stored procedure.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…