We are writing unit tests for our ASP.NET application that run against a test SQL Server database. That is, the ClassInitialize method creates a new database with test data, and the ClassCleanup deletes the database. We do this by running .bat scripts from code.
The classes under test are given a connection string that connects to the unit test database rather than a production database.
Our problem is, that the database contains a full text index, which needs to be fully populated with the test data in order for our tests to run as expected.
As far as I can tell, the fulltext index is always populated in the background. I would like to be able to either:
- Create the full text index, fully populated, with a synchronous (transact-SQL?) statement, or
- Find out when the fulltext population is finished, is there a callback option, or can I ask repeatedly?
My current solution is to force a delay at the end the class initialize method - 5 seconds seems to work - because I can't find anything in the documentation.
This is a stored procedure we created based on GarethOwen's answer. It accepts a comma separated list of tables as parameters and waits until full text indexes on all of them have been updated. It does this check every tenth of a second to prevent thrashing the disk and times out after 10 seconds just in case things are running slowly/broken. Useful if your FT searches are across multiple indexes.
Called in the following way:
The source:
dbo.split is a table value function that everyone must have by now which splits a string on a separator into a temporary table:
I would like to offer an easier-to-read version of @Daniel Renshaw's answer:
Results:
To wait for a full text catalog to finish population of all its tables and views without having to specify their names, you can use the following stored procedure. This is a combination of JohnB's answer to this question and the answer by cezarm to a related question:
Thanks Daniel, your answer got me on the right track.
I actually use the following T-SQL statement to ask if the population status of the full text index is Idle:
'v_doc_desc_de' is the name of the database view that we index.
If the population status is not idle, I wait a couple of seconds and ask again, until it is Idle. It is important to wait a small amount of time between checks to ensure the full text population is not slowed down by continuously checking the population status.
The MSDN documentation states that the
OBJECTPROPERTYEX
function (at table level) is recommended over theFULLTEXTCATALOGPROPERTY
statement with property 'PopulateStatus'. It states the following:You can query the status using FULLTEXTCATALOGPROPERTY (see here: http://technet.microsoft.com/en-us/library/ms190370.aspx).
For example:
You might also like to use SQL Profiler to monitor what commands SQL Server Management Studio issues when you bring up the properties dialog for the catalog. The dialog includes an indicatin of population status and all the information shown is queried using T-SQL.