Sql-Server

在 Azure DevOps 上部署 SQL Server 數據庫的問題

  • January 27, 2022

我們在通過數據庫解決方案中的 Azure Devops 部署數據庫時遇到問題:

2022-01-26T09:10:26.6741963Z Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
2022-01-26T09:10:26.6742889Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.DeploymentScriptDomGenerator.UnbindTableDatamotion(SqlTable sourceTable, SqlTable targetTable, Boolean unbindPartitionScheme, HashSet`1 unboundColumns)
2022-01-26T09:10:26.6744135Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.DeploymentScriptDomGenerator.GenerateUnbindTableSteps(SqlTable sourceTable, SqlTable targetTable)
2022-01-26T09:10:26.6746179Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.DeploymentScriptDomGenerator.GenerateSteps(Int32 operation, IModelElement element)
2022-01-26T09:10:26.6747124Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.Analyzers.PlanMediator.BuildDependencyOrderedSteps(Int32 operation, List`1 classOrder, List`1 operationOrder, Dictionary`2 changes, Boolean preserveGraphs, Dictionary`2& relating, Dictionary`2& related)
2022-01-26T09:10:26.6747886Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.Analyzers.PlanMediator.BuildOperations()
2022-01-26T09:10:26.6748373Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.OnGeneratePlan()
2022-01-26T09:10:26.6748954Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeploymentPlanGenerator.GeneratePlan(List`1 drops)
2022-01-26T09:10:26.6749433Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.BuildPlan()
2022-01-26T09:10:26.6749865Z    at Microsoft.Data.Tools.Schema.Sql.Deployment.SqlDeployment.Controller.CreatePlan()
2022-01-26T09:10:26.6750293Z    at Microsoft.SqlServer.Dac.DeployOperation.<>c__DisplayClass3.<>c__DisplayClass5.<CreatePlanInitializationOperation>b__1()
2022-01-26T09:10:26.6750692Z    at Microsoft.Data.Tools.Schema.Sql.Dac.OperationLogger.Capture(Action action)
2022-01-26T09:10:26.6751115Z    at Microsoft.SqlServer.Dac.DeployOperation.<>c__DisplayClass3.<CreatePlanInitializationOperation>b__0(Object operation, CancellationToken token)
2022-01-26T09:10:26.6751530Z    at Microsoft.SqlServer.Dac.Operation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
2022-01-26T09:10:26.6751996Z    at Microsoft.SqlServer.Dac.ReportMessageOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
2022-01-26T09:10:26.6752488Z    at Microsoft.SqlServer.Dac.OperationExtension.CompositeOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
2022-01-26T09:10:26.6752950Z    at Microsoft.SqlServer.Dac.OperationExtension.CompositeOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
2022-01-26T09:10:26.6753456Z    at Microsoft.SqlServer.Dac.DeployOperation.Microsoft.SqlServer.Dac.IOperation.Run(OperationContext context)
2022-01-26T09:10:26.6753964Z    at Microsoft.SqlServer.Dac.OperationExtension.Execute(IOperation operation, DacLoggingContext loggingContext, CancellationToken cancellationToken)
2022-01-26T09:10:26.6754586Z    at Microsoft.SqlServer.Dac.DacServices.InternalDeploy(IPackageSource packageSource, Boolean isDacpac, String targetDatabaseName, DacDeployOptions options, CancellationToken cancellationToken, DacLoggingContext loggingContext, Action`3 reportPlanOperation, Boolean executePlan)
2022-01-26T09:10:26.6757007Z    at Microsoft.SqlServer.Dac.DacServices.Deploy(DacPackage package, String targetDatabaseName, Boolean upgradeExisting, DacDeployOptions options, Nullable`1 cancellationToken)
2022-01-26T09:10:26.6757864Z    at Microsoft.Data.Tools.Schema.CommandLineTool.DacServiceUtil.<>c__DisplayClassd.<DoDeployAction>b__2(DacServices service)
2022-01-26T09:10:26.6758615Z    at Microsoft.Data.Tools.Schema.CommandLineTool.DacServiceUtil.ExecuteDeployOperation(CommandLineArguments cmdlineArgs, String connectionString, String filePath, String modelFilePath, MessageWrapper messageWrapper, Boolean sourceIsPackage, Boolean targetIsPackage, Boolean authType, String tenantId, String customAuthArgs, Func`1 generateScriptFromPackage, Func`2 generateScriptFromDatabase)
2022-01-26T09:10:26.6759486Z    at Microsoft.Data.Tools.Schema.CommandLineTool.DacServiceUtil.DoDeployAction(DeployArguments deployArgs, Action`1 writeError, Action`2 writeMessage, Action`1 writeWarning, CancellationToken cancellationToken, CommandLineArguments cmdlineArgs)
2022-01-26T09:10:26.6760035Z    at Microsoft.Data.Tools.Schema.CommandLineTool.Program.DoDeployActions(CommandLineArguments parsedArgs)
2022-01-26T09:10:26.6760422Z    at Microsoft.Data.Tools.Schema.CommandLineTool.Program.PerformAction(CommandLineArguments parsedArgs)
2022-01-26T09:10:26.6760761Z    at Microsoft.Data.Tools.Schema.CommandLineTool.Program.Run(String[] args)
2022-01-26T09:10:26.6761067Z    at Microsoft.Data.Tools.Schema.CommandLineTool.Program.Main(String[] args)

同樣奇怪的是,當我們在空數據庫上部署項目時一切正常。當我們想在現有數據庫上部署時,問題就開始了。

嗯,這個錯誤通常與 sqlpackage 不是最新的有關。

問題不在於新數據庫,因為它不需要進行模式比較。嘗試更新目標伺服器中的 dacfx。

引用自:https://dba.stackexchange.com/questions/306612