Friday, February 24, 2012

Full-Text Search gets syntax error and kills the transaction

I am having problems with syntax errors being generated from the search clause of a full-text search. When the syntax error is raised, the batch and transaction are stopped. Placing the search within a SQL Try/Catch allows the batch to continue, but the transaction is uncommitable.

I need to trap and handle the full-text search syntax error then control the commit or rollback of the transaction based on other transactions.

Below is a simplified version of the type of logic I am working with. The XACT_STATE goes to -1 because of the syntax error generated by the full-text search. This forces a rollback of the whole transaction.

Declare@.sSearch NVarChar(50)

/* @.sSearch is passed by a web page and could come back empty or with an invalid Full-Text search clause*/

Begin Transaction

Begin Try

Print XACT_STATE()

Select*

/*The table 'KnowledgeBase' is a table with a populated Full-Text Search*/

FromContainstable(KnowledgeBase,*,@.sSearch)

End Try

Begin Catch

Print XACT_STATE()

Print 'Number- ' + Convert(VarChar,ERROR_NUMBER()) + ', ' +

'Severity- ' + Convert(VarChar,ERROR_SEVERITY()) + ', ' +

'State- ' + Convert(VarChar,ERROR_STATE()) + ', ' +

'Message- "' + ERROR_MESSAGE() + '"'

End Catch

/*Some other logic would be here*/

Commit Transaction

I'm moving this post to the Transact-SQL forum because it's a better venue for code-related questions.

Regards,

Gail

No comments:

Post a Comment