views:

132

answers:

1

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

+2  A: 
sp_fulltext_database 'enable'

It's a string parameter, not a reserved word.

EDIT BY KENT: I marked as answer to give Quassnoi the rep. But to elaborate, if I add my USE database statement to the top of my script, it works. For reasons I don't understand, it doesn't work when I execute the USE database as a separate statement inside the same session (see my original code).

Quassnoi
Nope - same problem. Cannot use full-text search in master, tempdb, or model database.
Kent Boogaart
Then you are using `master`, `tempdb` or `model`. Could you please run the script in the `SSMS` (making sure that correct database is selected in the combo box in the upper left corner) and check if the problem persists?
Quassnoi
Cheers Quassnoi - that was driving me insane.
Kent Boogaart