2011-10-04 108 views
1

我有許多SQL Server 2008數據庫項目在Visual Studio 2010中的解決方案。我試圖做一個「部署解決方案」,我發現了以下錯誤數據庫pojects之一:VS2010數據庫項目部署 - 「SqlDeployTask」任務意外失敗,NullReferenceException

------ Deploy started: Project: MyDBProj, Configuration: Sandbox Any CPU ------ 
C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.TSqlTasks.targets(120,5): Error MSB4018: The "SqlDeployTask" task failed unexpectedly. 
System.NullReferenceException: Object reference not set to an instance of an object. 
    at Microsoft.Data.Schema.Sql.SchemaModel.SqlModelComparerBase.VariableSubstitution(SqlScriptProperty propertyValue, IDictionary`2 variables, Boolean& isChanged) 
    at Microsoft.Data.Schema.Sql.SchemaModel.SqlModelComparerBase.ArePropertiesEqual(IModelElement source, IModelElement target, ModelPropertyClass propertyClass, ModelComparerConfiguration configuration) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareProperties(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonChangeDefinition changes) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithoutCompareName(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithSameType(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean ignoreComparingName, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, Boolean compareFromRootElement, ModelComparisonChangeDefinition& changes) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareChildren(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareParentElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes, Boolean isComposing) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithoutCompareName(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithSameType(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean ignoreComparingName, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, Boolean compareFromRootElement, ModelComparisonChangeDefinition& changes) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareChildren(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareParentElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes, Boolean isComposing) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithoutCompareName(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, ModelComparisonResult result, ModelComparisonChangeDefinition changes) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareElementsWithSameType(IModelElement sourceElement, IModelElement targetElement, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean ignoreComparingName, Boolean parentExplicitlyIncluded, Boolean compareElementOnly, Boolean compareFromRootElement, ModelComparisonChangeDefinition& changes) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareAllElementsForOneType(ModelElementClass type, ModelComparerConfiguration configuration, ModelComparisonResult result, Boolean compareOrphanedElements) 
    at Microsoft.Data.Schema.SchemaModel.ModelComparer.CompareStore(ModelStore source, ModelStore target, ModelComparerConfiguration configuration) 
    at Microsoft.Data.Schema.Build.SchemaDeployment.CompareModels() 
    at Microsoft.Data.Schema.Build.SchemaDeployment.PrepareBuildPlan() 
    at Microsoft.Data.Schema.Build.SchemaDeployment.Execute(Boolean executeDeployment) 
    at Microsoft.Data.Schema.Build.SchemaDeployment.Execute() 
    at Microsoft.Data.Schema.Tasks.DBDeployTask.Execute() 
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 
    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) 
    Done executing task "SqlDeployTask" -- FAILED. 
    Done building target "DspDeploy" in project "MyDBProj.dbproj" -- FAILED. 
Done executing task "CallTarget" -- FAILED. 
Done building target "DBDeploy" in project "MyDBProj.dbproj" -- FAILED. 
Done building project "MyDBProj.dbproj" -- FAILED. 

有誰知道這可能是導致此?

我的項目被配置爲創建部署腳本並針對目標數據庫運行它。 我試過在運行部署之前刪除目標數據庫並創建一個空數據庫。 我試過'清理'Visual Studio中的解決方案。

回答

0

我已經能夠重現此錯誤含有單內聯函數如下測試數據庫項目:

CREATE FUNCTION [dbo].[Function1] 
() 
RETURNS TABLE 
AS 
    RETURN (
     WITH cte AS (
      SELECT 1 AS [c1] 
      FROM [$(Database3)].[dbo].[Table1] 
     ) 
     SELECT 1 AS [c1] 
     FROM cte 
    ) 

$(Database3)是一個數據庫變量引用另一個數據庫項目.dbschema文件。這個dbschema文件包含一個表格 - [Table1]

看來你需要一個CTE的內聯函數,它包含了使用數據庫變量的另一個數據庫的引用。此外,該功能必須已經存在於目標數據庫中。

你可能會在某些情況下出現以下錯誤(如內聯函數不使用CTE):

------ Deploy started: Project: Database2, Configuration: Debug Any CPU ------ 
Database2.dbschema(0,0): Warning TSD00560: If this deployment is executed, changes to [dbo].[Function2] might introduce run-time errors in [dbo].[Procedure1]. 
    Deployment script generated to: 
C:\temp\Database2\sql\debug\Database2.sql 

    Altering [dbo].[Function2]... 
C:\temp\Database2\sql\debug\Database2.sql(74,0): Error SQL01268: .Net SqlClient Data Provider: Msg 208, Level 16, State 1, Procedure Function2, Line 9 Invalid object name 'Database3.dbo.Table1'. 
    An error occurred while the batch was being executed. 
    Done executing task "SqlDeployTask" -- FAILED. 
    Done building target "DspDeploy" in project "Database2.dbproj" -- FAILED. 
Done executing task "CallTarget" -- FAILED. 
Done building target "DBDeploy" in project "Database2.dbproj" -- FAILED. 
Done building project "Database2.dbproj" -- FAILED. 

Build FAILED. 

所以,唯一的解決方法似乎是部署之前刪除函數中的目標。

我會引發Microsoft Connect問題。

UPDATE

我創建了一個連接的問題 - https://connect.microsoft.com/VisualStudio/feedback/details/693158/vs2010-database-project-deploy-sqldeploytask-task-failed-unexpectedly-nullreferenceexception

相關問題