2017-09-20 37 views
2

我在我的SQL Server數據庫項目中有很多時態表。今天,我將SSDT升級到最新版本,並且在構建項目時出現時態表的以下錯誤。例如,我有一個臨時表UseCase,它有一個名爲UseCase_HISTORY的歷史表。SQL Server時態表的SSDT代碼分析錯誤

它看起來像一個代碼分析問題。如果我在構建上禁用代碼分析,則構建時不會出現錯誤。

我正在使用VS2015和VS2017。兩者都有同樣的問題。

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(1292,5): Error: SQL72039: The substring is out of the bounds for script MSSQL::dbo.UseCase_HISTORY. 
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets(1292,5): Error: MSB4018: The "SqlStaticCodeAnalysisTask" task failed unexpectedly. 
Microsoft.Data.Tools.Schema.SchemaModel.ScriptCacheException: The substring is out of the bounds for script MSSQL::dbo.UseCase_HISTORY. 
    at Microsoft.Data.Tools.Schema.SchemaModel.ScriptCache.CheckAndGetSubstring(String cacheIdentifier, Int32 startOffset, Int32 length, CachedString value) 
    at Microsoft.Data.Tools.Schema.SchemaModel.ScriptCache.GetScript(String cacheIdentifier, Int32 startOffset, Int32 length) 
    at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlSourceInformation.ParseSource() 
    at Microsoft.Data.Tools.Schema.Sql.SchemaModel.SqlSourceInformation.get_ScriptDom() 
    at Microsoft.SqlServer.Dac.Model.SqlSchemaModelObjectService.GetOriginalSourceFragment(TSqlObject tSqlObject) 
    at Microsoft.SqlServer.Dac.TSqlModelUtils.TryGetFragmentForAnalysis(TSqlObject tSqlObject, TSqlFragment& fragment) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.SqlRuleExecutionContext.get_ScriptFragment() 
    at Microsoft.SqlServer.Dac.CodeAnalysis.Rules.Design.DataTypeCompatibilityRule.Analyze(SqlRuleExecutionContext context) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.Engine.RuleEngine.TryExecuteSingleRule(RuleDescriptor ruleDescriptor, SqlRuleExecutionContext executionContext) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.Engine.RuleEngine.ExecuteSingleRule(RuleDescriptor ruleDescriptor, SqlRuleExecutionContext executionContext, IList`1 errors) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.Engine.RuleEngine.ExecuteRules(SqlRuleExecutionContext executionContext, IEnumerable`1 rules, IList`1 allErrors) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.Engine.RuleEngine.ExecuteElementRules(TSqlModel schemaModel, List`1 allErrors, IEnumerable`1 modelElements, ISet`1 rules, List`1 allProblems) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.Engine.RuleEngine.ExecuteElementRules(TSqlModel schemaModel, List`1 allErrors) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.Engine.RuleEngine.ExecuteRules(TSqlModel schemaModel, IList`1& errors) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.CodeAnalysisService.ExecuteProcessRulesStep() 
    at Microsoft.SqlServer.Dac.CodeAnalysis.CodeAnalysisService.ExecuteStep(Func`1 step) 
    at Microsoft.SqlServer.Dac.CodeAnalysis.CodeAnalysisService.Execute() 
    at Microsoft.SqlServer.Dac.CodeAnalysis.CodeAnalysisService.Analyze(TSqlModel model) 
    at Microsoft.Data.Tools.Schema.Tasks.Sql.SqlStaticCodeAnalysisTask.ExecuteProcessRulesStep() 
    at Microsoft.Data.Tools.Schema.Tasks.Sql.SqlStaticCodeAnalysisTask.ExecuteStep(Func`1 step) 
    at Microsoft.Data.Tools.Schema.Tasks.Sql.SqlStaticCodeAnalysisTask.Execute() 
    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 
    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() 
+0

我有同樣的問題,你有沒有找到問題所在? –

+0

@AramGevorgyan你能看看我的答案嗎?如果相同的臨時解決方法對您也有幫助,我會對此進行一些故障排除。 –

+0

@BrianJorden:是的,當我取消選中SR0014時有幫助,但我沒有申報UDT。我有這些錯誤,只有在一些桌子上,並非全部。 –

回答

0

我有你呈現後,我升級SSMS/SSDT/DACFX都在同一時間17.3版本同樣的錯誤(是個很愚蠢的舉動做一次全部)。在我的情況下,我至少把這個問題縮小了一大堆。

我還沒有能夠在新項目中完全複製此問題,但它似乎與代碼分析設置中的SR0014選項直接相關。只要我把這個特定的選項關閉,一切都開始工作了。

enter image description here

我想你可能有問題的斑點部分,時態表/歷史記錄表,因爲我利用他們廣泛的爲好。根據拋出硬錯誤的特定規則,我們的設計中可能會有另一個共同點。你是否也在使用用戶定義的數據類型在同一張表上拋出錯誤?爲了保持一致性和下游使用,我基本上使用了所有數據類型的別名。

我目前的預感是這個錯誤與多個時態表和用戶定義的數據類型的組合有關。您是否可以確認您是否也在使用這些工具,並且如果取消選中SR0014,您可以構建您的項目?作爲一個側面說明,我將目標鎖定爲具有140個兼容級別的Azure SQL數據庫。

如果是這種情況,可能是受影響的用戶中的很小一部分,我們需要實際報告這一情況。