Pivot Runner null command

不问归期 提交于 2019-12-20 04:13:49

问题


While updating existing schema with PivotRunner on an existing database, I'm facing the error presented below.

I can't figure out why view may return an empty command. What are the most plausible cases ? If going over this error, I would have same error with a procedure, what should I check ?

Thanks for your answer,

    {System.ArgumentNullException: Value cannot be null.
Parameter name: command
   at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.ExecuteNonQuery(String command, Boolean incrementChangesCount)
   at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.UpdateView(PivotRunnerView view, View existingView)
   at CodeFluent.Runtime.Database.Management.SqlServer.PivotRunner.Run()
   at CodeFluentAssociationMigration.MigrateAssociationsDB.migrate(String associationModelPath, String connectionString) in C:\MyPath\MyProgram.cs:line 190
   at CodeFluentAssociationMigration.Program.Main(String[] args) in C:\MyPath\MyProgram.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()}

The only trace I have in my log file is as below:

[04/04/2016 12:18:47] : Checking unique keys...
[04/04/2016 12:18:47] : Checking views...

EDIT: These are the views elements of my pivot file

  <views>
    <view name="vAccount" schema="Association">
      CREATE VIEW [Association].[vAccount]
      AS
      SELECT [Association].[Account].[Account_AccountId], [Association].[Account].[Account_Label], [Association].[Account].[Account_NumberInt], [Association].[Account].[Account_NumberExt], [Association].[Account].[Account_InitialValue], [Association].[Account].[Account_AccountType_AccountTypeId], [Association].[Account].[Account_AccountCategory_AccountCategoryId], [Association].[Account].[Account_IsUsedByDefault], [Association].[Account].[Account_IsDeactivated], [Association].[Account].[Account_IsReadyForClosure], [Association].[Account].[_rowVersion], [Association].[Account].[_trackCreationTime], [Association].[Account].[_trackLastWriteTime], [Association].[Account].[_trackCreationUser], [Association].[Account].[_trackLastWriteUser]
      FROM [Association].[Account]
    </view>
    <view name="vAccountBalanceHistory" schema="Association">
      CREATE VIEW [Association].[vAccountBalanceHistory]
      AS
      SELECT [Association].[AccountBalanceHistory].[AccountBalanceHistory_AccountBalanceHistoryId], [Association].[AccountBalanceHistory].[AccountBalanceHistory_AccountingPeriod_AccountingPeriodId], [Association].[AccountBalanceHistory].[AccountBalanceHistory_Account_AccountId], [Association].[AccountBalanceHistory].[AccountBalanceHistory_DebitBalance], [Association].[AccountBalanceHistory].[AccountBalanceHistory_CreditBalance], [Association].[AccountBalanceHistory].[_rowVersion], [Association].[AccountBalanceHistory].[_trackCreationTime], [Association].[AccountBalanceHistory].[_trackLastWriteTime], [Association].[AccountBalanceHistory].[_trackCreationUser], [Association].[AccountBalanceHistory].[_trackLastWriteUser]
      FROM [Association].[AccountBalanceHistory]
    </view>
    <view name="vAccountCategory" schema="Association">
      CREATE VIEW [Association].[vAccountCategory]
      AS
      SELECT [Association].[AccountCategory].[AccountCategory_AccountCategoryId], [Association].[AccountCategory].[AccountCategory_Number], [Association].[AccountCategory].[AccountCategory_Label], [Association].[AccountCategory].[_rowVersion], [Association].[AccountCategory].[_trackCreationTime], [Association].[AccountCategory].[_trackLastWriteTime], [Association].[AccountCategory].[_trackCreationUser], [Association].[AccountCategory].[_trackLastWriteUser]
      FROM [Association].[AccountCategory]
    </view>
    <view name="vAccountingEntry" schema="Association">
      CREATE VIEW [Association].[vAccountingEntry]
      AS
      SELECT [Association].[AccountingEntry].[AccountingEntry_AccountingEntryId], [Association].[AccountingEntry].[AccountingEntry_Date], [Association].[AccountingEntry].[AccountingEntry_Label], [Association].[AccountingEntry].[AccountingEntry_Debit], [Association].[AccountingEntry].[AccountingEntry_Credit], [Association].[AccountingEntry].[AccountingEntry_DocumentNumber], [Association].[AccountingEntry].[AccountingEntry_Account_AccountId], [Association].[AccountingEntry].[AccountingEntry_TVA_TVAId], [Association].[AccountingEntry].[AccountingEntry_PaymentMode], [Association].[AccountingEntry].[AccountingEntry_LabelAdditional], [Association].[AccountingEntry].[AccountingEntry_Status], [Association].[AccountingEntry].[AccountingEntry_EntryType], [Association].[AccountingEntry].[_rowVersion], [Association].[AccountingEntry].[_trackCreationTime], [Association].[AccountingEntry].[_trackLastWriteTime], [Association].[AccountingEntry].[_trackCreationUser], [Association].[AccountingEntry].[_trackLastWriteUser]
      FROM [Association].[AccountingEntry]
    </view>
    <view name="vAccountingPeriod" schema="Association">
      CREATE VIEW [Association].[vAccountingPeriod]
      AS
      SELECT [Association].[AccountingPeriod].[AccountingPeriod_AccountingPeriodId], [Association].[AccountingPeriod].[AccountingPeriod_DateStart], [Association].[AccountingPeriod].[AccountingPeriod_DateEnd], [Association].[AccountingPeriod].[AccountingPeriod_IsClosed], [Association].[AccountingPeriod].[AccountingPeriod_LedgerURL], [Association].[AccountingPeriod].[AccountingPeriod_BalanceURL], [Association].[AccountingPeriod].[AccountingPeriod_ProfitAndLossURL], [Association].[AccountingPeriod].[_rowVersion], [Association].[AccountingPeriod].[_trackCreationTime], [Association].[AccountingPeriod].[_trackLastWriteTime], [Association].[AccountingPeriod].[_trackCreationUser], [Association].[AccountingPeriod].[_trackLastWriteUser]
      FROM [Association].[AccountingPeriod]
    </view>
    <view name="vAccountType" schema="Association">
      CREATE VIEW [Association].[vAccountType]
      AS
      SELECT [Association].[AccountType].[AccountType_AccountTypeId], [Association].[AccountType].[AccountType_Label], [Association].[AccountType].[AccountType_Group], [Association].[AccountType].[_rowVersion], [Association].[AccountType].[_trackCreationTime], [Association].[AccountType].[_trackLastWriteTime], [Association].[AccountType].[_trackCreationUser], [Association].[AccountType].[_trackLastWriteUser]
      FROM [Association].[AccountType]
    </view>
    <view name="vAssociation" schema="Global">
      CREATE VIEW [Global].[vAssociation]
      AS
      SELECT [Global].[Association].[Association_AssociationId], [Global].[Association].[Association_PrefectureNumber], [Global].[Association].[Association_NumberExt], [Global].[Association].[Association_Label], [Global].[Association].[Association_IsActive], [Global].[Association].[Association_Schema], [Global].[Association].[_rowVersion], [Global].[Association].[_trackCreationTime], [Global].[Association].[_trackLastWriteTime], [Global].[Association].[_trackCreationUser], [Global].[Association].[_trackLastWriteUser]
      FROM [Global].[Association]
    </view>
    <view name="vAssociationUser" schema="Global">
      CREATE VIEW [Global].[vAssociationUser]
      AS
      SELECT [Global].[AssociationUser].[AssociationUser_UserId], [Global].[AssociationUser].[AssociationUser_Association_AssociationId], [Global].[AssociationUser].[_rowVersion], [Global].[AssociationUser].[_trackCreationTime], [Global].[AssociationUser].[_trackLastWriteTime], [Global].[AssociationUser].[_trackCreationUser], [Global].[AssociationUser].[_trackLastWriteUser]
      FROM [Global].[AssociationUser]
    </view>
    <view name="vCardPeriod" schema="Global">
      CREATE VIEW [Global].[vCardPeriod]
      AS
      SELECT [Global].[CardPeriod].[CardPeriod_CardPeriodId], [Global].[CardPeriod].[CardPeriod_FromDate], [Global].[CardPeriod].[CardPeriod_ToDate], [Global].[CardPeriod].[CardPeriod_Season], [Global].[CardPeriod].[CardPeriod_TransferDate], [Global].[CardPeriod].[_rowVersion], [Global].[CardPeriod].[_trackCreationTime], [Global].[CardPeriod].[_trackLastWriteTime], [Global].[CardPeriod].[_trackCreationUser], [Global].[CardPeriod].[_trackLastWriteUser]
      FROM [Global].[CardPeriod]
    </view>
    <view name="vSupplier" schema="Global">
      CREATE VIEW [Global].[vSupplier]
      AS
      SELECT [Global].[Supplier].[Supplier_SupplierId], [Global].[Supplier].[Supplier_Label], [Global].[Supplier].[Supplier_NumberExt], [Global].[Supplier].[_rowVersion], [Global].[Supplier].[_trackCreationTime], [Global].[Supplier].[_trackLastWriteTime], [Global].[Supplier].[_trackCreationUser], [Global].[Supplier].[_trackLastWriteUser]
      FROM [Global].[Supplier]
    </view>
    <view name="vTVA" schema="Association">
      CREATE VIEW [Association].[vTVA]
      AS
      SELECT [Association].[TVA].[TVA_TVAId], [Association].[TVA].[TVA_DateStart], [Association].[TVA].[TVA_DateEnd], [Association].[TVA].[TVA_Rate], [Association].[TVA].[_rowVersion], [Association].[TVA].[_trackCreationTime], [Association].[TVA].[_trackLastWriteTime], [Association].[TVA].[_trackCreationUser], [Association].[TVA].[_trackLastWriteUser]
      FROM [Association].[TVA]
    </view>
  </views>

回答1:


It looks like you have formatted the xml document. The definition of the view now starts with a new line and some spaces, and the pivot runner doesn't like it. There are 2 solutions:

  • Don't change the generated file (the easiest solution)
  • Use a custom pivot runner as provided below that trims the definitions

In this code we create a class that inherits from the PivotRunner and we change the definition of views, procedures and functions.

using CodeFluent.Runtime;
using CodeFluent.Runtime.Database.Management.SqlServer;
using System;
using System.Xml;

public class CustomPivotRunner : PivotRunner
{
    public CustomPivotRunner(string packageFilePath) : base(packageFilePath)
    {
    }

    protected override PivotRunnerProcedure NewProcedure(XmlElement element)
    {
        return new CustomPivotRunnerProcedure(this, element);
    }

    protected override PivotRunnerView NewView(XmlElement element)
    {
        return new CustomPivotRunnerView(this, element);
    }

    protected override PivotRunnerFunction NewFunction(XmlElement element)
    {
        return new CustomPivotRunnerFunction(this, element);
    }
}

public class CustomPivotRunnerProcedure : PivotRunnerProcedure
{
    public CustomPivotRunnerProcedure(PivotRunner runner, XmlElement element) : base(runner, element)
    {
        Definition = Definition?.Trim();
    }
}

public class CustomPivotRunnerFunction : PivotRunnerFunction
{
    public CustomPivotRunnerFunction(PivotRunner runner, XmlElement element) : base(runner, element)
    {
        Definition = Definition?.Trim();
    }
}

public class CustomPivotRunnerView : PivotRunnerView
{
    public CustomPivotRunnerView(PivotRunner runner, XmlElement element) : base(runner, element)
    {
        Definition = Definition?.Trim();
    }
}

class Program
{
    static void Main(string[] args)
    {
        var logger = new Logger();
        PivotRunner pivotRunner = new CustomPivotRunner(@"MyModelpivot.xml");
        pivotRunner.ConnectionString = CodeFluentContext.Get("Sample").Persistence.ConnectionString;
        pivotRunner.Logger = logger;
        pivotRunner.Action += PivotRunner_Action;
        pivotRunner.Run();
    }

    private static void PivotRunner_Action(object sender, PivotRunnerEventArgs e)
    {
        Console.WriteLine(e.Type + " " + e.Options);
    }

    public class Logger : IServiceHost
    {
        public void Log(object value)
        {
            Console.WriteLine(value);
        }
    }
}


来源:https://stackoverflow.com/questions/36402244/pivot-runner-null-command

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!