Hi,
I'm trying to run a SQL script against SQL Server 2005 as part of the set up for my integration tests. The script works perfectly fine if I execute it from within SQL Server Management Studio. However, when executing programmatically, this part of the script that enables full-text search refuses to work:
-- lots of tables and indexes created above
create unique nonclustered index [IX_Id] on [MyTable] ( [Id] asc )
-- this line fails
sp_fulltext_database enable
create fulltext catalog MyCatalog with accent_sensitivity = off as default
create fulltext index on MyTable([Title],[Content]) key index IX_Id with change_tracking auto
The error I get is:
Incorrect syntax near 'enable'.
If I remove the lines related to full text, everything works fine. If I change the sp_fulltext_database enable
call to this:
EXEC ('sp_fulltext_database enable');
I get a different error:
Cannot use full-text search in master, tempdb, or model database.
This makes no sense to me at all. The correct database is in use.
For reference, the code that executes the script looks like this (I'm using NHibernate):
private static void InitializeDatabase()
{
var sessionFactory = new NHibernate.Cfg.Configuration().Configure().BuildSessionFactory();
using (var session = sessionFactory.OpenSession())
{
session.CreateSQLQuery("IF DB_ID('" + databaseName + @"') IS NOT NULL DROP DATABASE """ + databaseName + @""";").ExecuteUpdate();
session.CreateSQLQuery(@"CREATE DATABASE """ + databaseName + @""";").ExecuteUpdate();
session.CreateSQLQuery(@"USE """ + databaseName + @""";").ExecuteUpdate();
session.CreateSQLQuery(GetCreationScript()).ExecuteUpdate();
}
}
Can anyone tell me what I need to do to get this to work?
Thanks,
Kent