Sql server VS 2017数据库项目“;对对象的未解析引用”;错误

Sql server VS 2017数据库项目“;对对象的未解析引用”;错误,sql-server,sql-server-data-tools,Sql Server,Sql Server Data Tools,Microsoft SQL Server Visual Studio 2017数据工具(SSDT)版本15.7.4 我有一个数据仓库,我现在想用一个SSDT SQL Server数据库(SSDb)项目来管理它。DW有单独的提取/清理/转换/数据仓库数据库。我在主数据库中有许多SP和UDF。SP通过SP_MS_marksystemobject标记为系统过程。这些通用SP和UDF可用于所有DW数据库 我已经为每个数据库创建了一个SSDb项目,添加了对master的引用(无论是否勾选了Suppress

Microsoft SQL Server Visual Studio 2017数据工具(SSDT)版本15.7.4

我有一个数据仓库,我现在想用一个SSDT SQL Server数据库(SSDb)项目来管理它。DW有单独的提取/清理/转换/数据仓库数据库。我在主数据库中有许多SP和UDF。SP通过SP_MS_marksystemobject标记为系统过程。这些通用SP和UDF可用于所有DW数据库

我已经为每个数据库创建了一个SSDb项目,添加了对master的引用(无论是否勾选了Suppress errors复选框),并导入了带有所有选项的数据库对象(objects)勾选。我还选择了工具-->选项-->SQL Server工具-->联机编辑-->解析对系统视图和主数据库对象的引用。我已重新启动并重新启动SSDT

我发现以下错误:

------ Build started: Project: MyDWName, Configuration: Debug Any CPU ------
        C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /debug+ /debug:full /optimize- /out:obj\Debug\MyDWName.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /warnaserror- /utf8output "C:\Users\FUBAR\AppData\Local\Temp\.NETFramework,Version=v4.5.SqlClrAttributes.cs"
        Loading project references...
        Loading project files...
        Building the project model and resolving object interdependencies...
        Validating the project model...
Y:\SSIS\MySSDTSolution\MyDWName\Security\SAS_SQL_Admin.sql(1,1): Error:  SQL71501: User: [SAS_SQL_Admin] has an unresolved reference to Login [SAS_SQL_Admin].
Y:\SSIS\MySSDTSolution\MyDWName\Security\DOMAIN_user.sql(1,13): Error:  SQL70527: 'DOMAIN\user' is not a valid name because it contains characters that are not valid.
Y:\SSIS\MySSDTSolution\MyDWName\Security\DOMAIN_anotheruser.sql(2,27): Warning:  SQL71502: User: [DOMAIN\anotheruser] has an unresolved reference to Schema [DOMAIN\anotheruser].
Y:\SSIS\MySSDTSolution\MyDWName\dbo\Stored Procedures\uspDeleteTempTables.sql(10,67): Warning:  SQL71502: Procedure: [dbo].[uspDeleteTempTables] has an unresolved reference to object [sys].[sysprocesses].[spid].
Y:\SSIS\MySSDTSolution\MyDWName\dbo\Stored Procedures\uspDeleteTempTables.sql(10,26): Warning:  SQL71502: Procedure: [dbo].[uspDeleteTempTables] has an unresolved reference to object [sys].[sysprocesses].[nt_username].
Y:\SSIS\MySSDTSolution\MyDWName\dbo\Stored Procedures\uspDeleteTempTables.sql(10,44): Warning:  SQL71502: Procedure: [dbo].[uspDeleteTempTables] has an unresolved reference to object [sys].[sysprocesses].
Done building project "MyDWName.sqlproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
------ Build started: Project: MyDb (Databases\MyDb), Configuration: Debug Any CPU ------
        C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" /debug+ /debug:full /optimize- /out:obj\Debug\RLDX_Extract.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /warnaserror- /utf8output "C:\Users\FUBAR\AppData\Local\Temp\.NETFramework,Version=v4.6.1.SqlClrAttributes.cs"
        Loading project references...
        Loading project files...
        Building the project model and resolving object interdependencies...
        Validating the project model...
Y:\SSIS\MySSDTSolution\MyDWName\MyDb\meta\Views\vwJob_Status_Comma.sql(9,8): Error:  SQL71501: View: [meta].[vwJob_Status_Comma] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [master].[dbo].[fn_MoH_RightJustify] or [meta].[Job_Status].[master]::[dbo].[fn_MoH_RightJustify].
Y:\SSIS\MySSDTSolution2\MyDWName2\RLDX_Extract\meta\Views\vwJob_Status_Comma.sql(13,8): Error:  SQL71501: View: [meta].[vwJob_Status_Comma] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [master].[dbo].[fn_MoH_RightJustify] or [meta].[Job_Status].[master]::[dbo].[fn_MoH_RightJustify].
...
Y:\SSIS\MySSDTSolution\MyDWName\MyDb\Security\NSWDOH_anotheruser.sql(2,27): Warning:  SQL71502: User: [NSWDOH\anotheruser] has an unresolved reference to Schema [NSWDOH\anotheruser].
Done building project "RLDX_MyDb.sqlproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
对于SQL71502过程警告,如果我将sys.sysprocesss更改为master.sys.sysprocesss,警告就会消失。但是我有一个master的引用,这不应该起作用吗

对于SQL71501错误,我在用户名中没有看到任何无效字符。如果我将准确的代码粘贴到SSMS中,则没有错误。其他用户具有相同的域\用户名语法,但没有错误

对于SQL70527错误,该用户的默认架构为dbo,拥有的架构和成员身份为db_所有者。导入的文本为:

CREATE USER [SAS_SQL_Admin];
但是,在SSMS中为该用户编写脚本:

CREATE USER [SAS_SQL_Admin] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[dbo];
将此文本粘贴到SSDT中,错误消失了。三个小时的谷歌搜索解决了一个问题。这是SSDT中的错误吗?它不应该导入SSMS生成的相同定义吗

在另一个SSDb项目中,我遇到以下错误:

------ Build started: Project: MyDWName, Configuration: Debug Any CPU ------
        C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /debug+ /debug:full /optimize- /out:obj\Debug\MyDWName.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /warnaserror- /utf8output "C:\Users\FUBAR\AppData\Local\Temp\.NETFramework,Version=v4.5.SqlClrAttributes.cs"
        Loading project references...
        Loading project files...
        Building the project model and resolving object interdependencies...
        Validating the project model...
Y:\SSIS\MySSDTSolution\MyDWName\Security\SAS_SQL_Admin.sql(1,1): Error:  SQL71501: User: [SAS_SQL_Admin] has an unresolved reference to Login [SAS_SQL_Admin].
Y:\SSIS\MySSDTSolution\MyDWName\Security\DOMAIN_user.sql(1,13): Error:  SQL70527: 'DOMAIN\user' is not a valid name because it contains characters that are not valid.
Y:\SSIS\MySSDTSolution\MyDWName\Security\DOMAIN_anotheruser.sql(2,27): Warning:  SQL71502: User: [DOMAIN\anotheruser] has an unresolved reference to Schema [DOMAIN\anotheruser].
Y:\SSIS\MySSDTSolution\MyDWName\dbo\Stored Procedures\uspDeleteTempTables.sql(10,67): Warning:  SQL71502: Procedure: [dbo].[uspDeleteTempTables] has an unresolved reference to object [sys].[sysprocesses].[spid].
Y:\SSIS\MySSDTSolution\MyDWName\dbo\Stored Procedures\uspDeleteTempTables.sql(10,26): Warning:  SQL71502: Procedure: [dbo].[uspDeleteTempTables] has an unresolved reference to object [sys].[sysprocesses].[nt_username].
Y:\SSIS\MySSDTSolution\MyDWName\dbo\Stored Procedures\uspDeleteTempTables.sql(10,44): Warning:  SQL71502: Procedure: [dbo].[uspDeleteTempTables] has an unresolved reference to object [sys].[sysprocesses].
Done building project "MyDWName.sqlproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
------ Build started: Project: MyDb (Databases\MyDb), Configuration: Debug Any CPU ------
        C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\MSBuild\15.0\Bin\Roslyn\csc.exe /noconfig /nowarn:1701,1702,2008 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /errorendlocation /preferreduilang:en-US /highentropyva+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" /debug+ /debug:full /optimize- /out:obj\Debug\RLDX_Extract.dll /ruleset:"C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\Team Tools\Static Analysis Tools\\Rule Sets\MinimumRecommendedRules.ruleset" /subsystemversion:6.00 /target:library /warnaserror- /utf8output "C:\Users\FUBAR\AppData\Local\Temp\.NETFramework,Version=v4.6.1.SqlClrAttributes.cs"
        Loading project references...
        Loading project files...
        Building the project model and resolving object interdependencies...
        Validating the project model...
Y:\SSIS\MySSDTSolution\MyDWName\MyDb\meta\Views\vwJob_Status_Comma.sql(9,8): Error:  SQL71501: View: [meta].[vwJob_Status_Comma] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [master].[dbo].[fn_MoH_RightJustify] or [meta].[Job_Status].[master]::[dbo].[fn_MoH_RightJustify].
Y:\SSIS\MySSDTSolution2\MyDWName2\RLDX_Extract\meta\Views\vwJob_Status_Comma.sql(13,8): Error:  SQL71501: View: [meta].[vwJob_Status_Comma] contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any of the following objects: [master].[dbo].[fn_MoH_RightJustify] or [meta].[Job_Status].[master]::[dbo].[fn_MoH_RightJustify].
...
Y:\SSIS\MySSDTSolution\MyDWName\MyDb\Security\NSWDOH_anotheruser.sql(2,27): Warning:  SQL71502: User: [NSWDOH\anotheruser] has an unresolved reference to Schema [NSWDOH\anotheruser].
Done building project "RLDX_MyDb.sqlproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
以下是视图的定义:

CREATE VIEW [meta].[vwJob_Status_Comma] AS
SELECT Job_ID
    ,Job_Level
    ,Job_Name
    ,Job_RunDate
    ,Job_StartTime
    ,Job_EndTime
    ,master.dbo.fn_MoH_RightJustify(FORMAT(Job_ElapsedSeconds,'N0'),18,DEFAULT) AS Job_ElapsedSeconds
    ,Job_ElapsedTime
    ,DataExtract_StartTime
    ,DataExtract_EndTime
    ,master.dbo.fn_MoH_RightJustify(FORMAT(RowCountSource,'N0'),15,DEFAULT) AS RowCountSource
    ,master.dbo.fn_MoH_RightJustify(FORMAT(RowCountInserted,'N0'),15,DEFAULT) AS RowCountInserted
    ,master.dbo.fn_MoH_RightJustify(FORMAT(RowCountChanged,'N0'),15,DEFAULT) AS RowCountChanged
    ,master.dbo.fn_MoH_RightJustify(FORMAT(RowCountNoChange,'N0'),15,DEFAULT) AS RowCountNoChange
    ,master.dbo.fn_MoH_RightJustify(FORMAT(RowCountDeleted,'N0'),15,DEFAULT) AS RowCountDeleted
    ,master.dbo.fn_MoH_RightJustify(FORMAT(RowCountTarget,'N0'),15,DEFAULT) AS RowCountTarget
    ,Job_Step
    ,Job_Status
    ,SubmittedBy
FROM meta.Job_Status
问题:

1) 知道SSMS中的有效用户对象为什么会在SSDT中生成此错误吗:

“域\用户”不是有效名称,因为它包含无效字符

2) 我想管理SSDT项目中的用户对象。我更喜欢项目中对象的可见性。这是个坏主意/不是最佳做法吗

3) 此错误消息完全让我震惊:

[master].[dbo].[fn_MoH_RightJustify]或[meta].[Job_Status].[master]::[dbo].[fn_MoH_RightJustify]

什么是[meta].[Job\u Status].[master]::[dbo].[fn\u MoH\u RightJustify]???作业状态表中没有[master]列

4) SSDT是否导入了所有模式定义?我需要手动创建(部分)它们吗

5) DW数据库有很多同义词。SSDT是否正确处理同义词

谢谢

编辑: SP位于master中的原因是我需要它们在当前数据库连接的上下文中执行。我尝试了一个单独的工具数据库,但无法使其工作。看

既然SP在那里,我把UDF也放在那里以保持一致

我使用同义词而不是三级名称,即dbo.fn_MoH_CleanString而不是master.dbo.fn_MoH_CleanString

我想我开始“看到”这个问题了。当我添加对master的引用时,SSDT使用了基于我配置的sqlserver版本的master的静态副本。如果在编辑器中查看.sqlproj文件,我会看到:

<ItemGroup>
  <ArtifactReference Include="C:\Program Files (x86)\Microsoft Visual Studio\2017\SQL\Common7\IDE\Extensions\Microsoft\SQLDB\Extensions\SqlServer\130\SqlSchemas\master.dacpac">
    <HintPath>$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\130\SqlSchemas\master.dacpac</HintPath>
    <SuppressMissingDependenciesErrors>True</SuppressMissingDependenciesErrors>
    <DatabaseVariableLiteralValue>master</DatabaseVariableLiteralValue>
  </ArtifactReference>
</ItemGroup>
我应该在创建dacpac时关闭它吗