我试图对SQL Server 2005运行一个SQL脚本作为我的集成测试的一部分。如果我在SQL Server Management Studio中执行它,脚本工作得很好。但是,程序执行时,使全文搜索脚本的这部分拒绝工作:这个SQL脚本为什么失败?
-- 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
我得到的错误是:
Incorrect syntax near 'enable'.
如果我删除有关全文行,一切正常。如果我改变sp_fulltext_database enable
调用此:
EXEC ('sp_fulltext_database enable');
我得到一个不同的错误:
Cannot use full-text search in master, tempdb, or model database.
这没有任何意义,我在所有。正确的数据库是正在使用中。
仅供参考,执行脚本代码看起来像这样(我使用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();
}
}
谁能告诉我什么,我需要做的就是这个工作?
感谢,
肯特
没有 - 同样的问题。不能在master,tempdb或model数据库中使用全文搜索。 – 2010-01-20 12:26:23
然后你使用'master','tempdb'或'model'。您能否在SSMS中运行脚本(确保在左上角的组合框中选择了正确的数据库)并检查问题是否存在? – Quassnoi 2010-01-20 12:34:49
Cheers Quassnoi - 那让我疯狂。 – 2010-01-20 12:38:11