tags:

views:

35

answers:

1
return NHibernateSession.CreateQuery(@"TRUNCATE TABLE dbo.Exceptions").ExecuteUpdate();

Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [TRUNCATE TABLE Exceptions] Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [TRUNCATE TABLE Exceptions]

Source Error:

any idea why?

+4  A: 

TRUNCATE TABLE is not a valid HQL statement.

Use CreateSQLQuery instead of CreateQuery to execute SQL statements.

Diego Mijelshon
Yeah, that's the right answer.
Stefan Steinegger
thx for help Diego.
senzacionale
Off topic: Why does NHibernate expose an ANTLR exception? How is the user supposed to handle that? Shouldn't it should throw an InvalidQuerySyntaxException or whatnot?
Allon Guralnek
If you look closely, the NoViableAltException is wrapped in a QuerySyntaxException.
Diego Mijelshon