流利的迁移者不会创建同义词

时间:2014-08-12 04:18:51

标签: c# sql-server-2008 database-migration fluent-migrator

我正在使用Fluent Migrator 1.2.1

我在尝试创建同义词时遇到异常

Object reference not set to an instance of an object.

StackTrace:

   at FluentMigrator.Builders.Execute.ExecuteExpressionRoot.Sql(String sqlStatement)
   at Tavisca.Catapult.Database.Rates.Migrations._004TagsAtProductLevel.Up() in d:\Projects\IMS\Git Source\tavisca-catapult-databases\Tavisca.Catapult.Database.Migrations\Tavisca.Catapult.Database.Rates\Migrations\004TagsAtProductLevel.cs:line 27
   at Tavisca.Catapult.Database.Migrator.Program.Main(String[] args) in d:\Projects\IMS\Git Source\tavisca-catapult-databases\Tavisca.Catapult.Database.Migrations\Tavisca.Catapult.Database.Migrator\Program.cs:line 17
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

迁移代码如下

        var contentDbConnectionString =
            ConfigurationManager.ConnectionStrings["DBContent"].ConnectionString;

        var ratesDbConnectionString =
            ConfigurationManager.ConnectionStrings["DBRate"].ConnectionString;

        var contentDbConnectionStringBuilder = new SqlConnectionStringBuilder(contentDbConnectionString);

        var sqlConnectionBuilder = new SqlConnectionStringBuilder(ratesDbConnectionString);

        var command = "CREATE SYNONYM [dbo].[Table1] FOR [" + sqlConnectionBuilder.DataSource + "].[" + contentDbConnectionStringBuilder.InitialCatalog + "].[dbo].[Table1];" +
               "CREATE SYNONYM [dbo].[Table2] FOR [" + sqlConnectionBuilder.DataSource + "].["+ contentDbConnectionStringBuilder.InitialCatalog + "].[dbo].[Table2];";
        Execute.Sql(command); // Exception will come here.

相同的脚本在查询分析器中运行得非常好,同义词也可以。

0 个答案:

没有答案