title: Why is this SQL script failing?
body: <p>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:</p>
  
  <pre><code>-- 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
  </code></pre>
  
  <p>The error I get is:</p>
  
  <blockquote>
    <p>Incorrect syntax near 'enable'.</p>
  </blockquote>
  
  <p>If I remove the lines related to full text, everything works fine. If I change the <code>sp_fulltext_database enable</code> call to this:</p>
  
  <pre><code>EXEC ('sp_fulltext_database enable');
  </code></pre>
  
  <p>I get a different error:</p>
  
  <blockquote>
    <p>Cannot use full-text search in master,
    tempdb, or model database.</p>
  </blockquote>
  
  <p>This makes no sense to me at all. The correct database <em>is</em> in use.</p>
  
  <p>For reference, the code that executes the script looks like this (I'm using NHibernate):</p>
  
  <pre><code>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();
      }
  }
  </code></pre>
  
  <p>Can anyone tell me what I need to do to get this to work?</p>
  
  <p>Thanks,<br>
  Kent</p>