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

时间:2018-06-27 08:07:09

标签: sql-server sql-server-data-tools

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

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

我为每个数据库创建了一个SSDb项目,添加了对master的引用(勾选和不勾选抑制错误复选框,并在勾选了所有选项(对象)的情况下导入了数据库对象。我还选择了工具- ->选项-> 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 ==========

对于SQL71502程序警告,如果将sys.sysprocesses更改为master.sys.sysprocesses,该警告将消失。但是我有一个大师的参考,不应该这样吗?

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

对于SQL70527错误,它是默认模式为dbo,拥有模式和成员资格为db_owner的用户。导入的文本为:

CREATE USER [SAS_SQL_Admin];

但是,在SSMS中为该用户编写脚本:

CREATE USER [SAS_SQL_Admin] WITHOUT LOGIN WITH DEFAULT_SCHEMA=[dbo];

将此文本粘贴到SSDT中,错误消失了。三个小时的谷歌搜索,解决了一个问题。这是SSDT中的错误吗?它不应该导入SSMS生成的相同定义吗?

在另一个SSDb项目中,出现以下错误:

------ 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中产生此错误:

  

'DOMAIN \ user'是无效名称,因为它包含无效字符。

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

3)此错误消息完全抛出了我:

  

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

什么是[meta]。[Job_Status]。[master] :: [dbo]。[fn_MoH_RightJustify] ??? Job_Status表中没有[master]列。

4)SSDT是否导入了所有模式定义?我需要手动创建(其中一些)吗?

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

谢谢...

编辑: SP在主服务器中的原因是我需要它们在当前数据库连接的上下文中执行。我尝试了一个单独的Tools数据库,但无法正常工作。参见http://sqlserverplanet.com/dba/making-a-procedure-available-in-all-databases

由于SP在那里,所以我也将UDF放在那里以保持一致。

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

我认为我开始“看到”问题了。当我添加对master的引用时,SSDT根据我配置的SQL Server版本使用master的 static 副本。如果在编辑器中查看.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>

我认为对master的引用导致对master的动态运行时检查。

我无法从SSMS创建主控制器的dacpac-SSMS的缺点-但可以从SSDT创建。但是,我收到此错误:

/****** Operation Steps ******/
Step 'Extracting schema from database'. Progress: Pending
Step 'Resolving references in schema model'. Progress: Pending
Step 'Validating schema model'. Progress: Pending
Step 'Extracting schema'. Progress: Pending
Step 'Extracting schema'. Progress: Running
Step 'Extracting schema from database'. Progress: Running
Step 'Extracting schema from database'. Progress: Completed
Step 'Resolving references in schema model'. Progress: Running
Step 'Resolving references in schema model'. Progress: Completed
Step 'Validating schema model'. Progress: Running
Step 'Validating schema model'. Progress: Failed
Step 'Extracting schema'. Progress: Failed

/****** Logged Messages ******/
Extracting schema (Start)
Gathering error messages
Gathering cryptographic providers
Gathering credentials
Gathering logins
Gathering server roles
Gathering server role memberships
Gathering linked servers
Gathering linked server logins
Gathering routes
Gathering ddl triggers
Gathering encrypted and clr ddl triggers
Gathering event notifications
Gathering server audits
Gathering server audit specifications
Gathering event notifications
Gathering database options
Gathering users
Gathering roles
Gathering application roles
Gathering role memberships
Gathering filegroups
Gathering files
Gathering full-text catalogs
Gathering assemblies
Gathering certificates
Gathering asymmetric keys
Gathering symmetric keys
Gathering encrypted symmetric keys
Gathering database encryption keys
Gathering schemas
Gathering XML schema collections
Gathering user-defined data types
Gathering user-defined types
Gathering table types
Gathering unique keys for table types
Gathering primary keys for table types
Gathering check constraints for table types
Gathering default constraints for table types
Gathering partition functions
Gathering partition schemes
Gathering functions
Gathering encrypted functions
Gathering aggregates
Gathering procedures
Gathering procedures
Gathering encrypted procedures
Gathering encrypted procedures
Gathering encrypted procedures
Gathering tables
Gathering tables
Gathering primary keys
Gathering unique constraints
Gathering foreign keys
Gathering default constraints
Gathering check constraints
Gathering views
Gathering encrypted views
Gathering indexes
Gathering statistics
Gathering full-text index stoplists
Gathering search property lists
Gathering search properties
Gathering full-text indexes
Gathering column store indexes
Gathering spatial indexes
Gathering XML indexes
Gathering Selective XML indexes
Gathering encrypted triggers
Gathering triggers
Gathering encrypted and clr ddl triggers
Gathering ddl triggers
Gathering synonyms
Gathering defaults
Gathering data constraint uddt bindings
Gathering rules
Gathering data constraint uddt bindings
Gathering message types
Gathering queues
Gathering contracts
Gathering services
Gathering routes
Gathering event notifications
Gathering remote service bindings
Gathering broker priorities
Gathering database audit specifications
Gathering signatures
Gathering signatures
Gathering data compression options
Gathering sequence types
Gathering extended properties
Gathering extended properties
Gathering extended properties
Gathering extended properties
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] has an unresolved reference to object [SSISDB].[catalog].[packages].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] has an unresolved reference to object [SSISDB].[catalog].[projects].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[packages].[p], [SSISDB].[catalog].[packages].[project_id] or [SSISDB].[catalog].[projects].[p].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[packages].[j], [SSISDB].[catalog].[projects].[j] or [SSISDB].[catalog].[projects].[project_id].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] has an unresolved reference to object [SSISDB].[catalog].[folders].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[j], [SSISDB].[catalog].[packages].[j], [SSISDB].[catalog].[projects].[folder_id] or [SSISDB].[catalog].[projects].[j].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[f], [SSISDB].[catalog].[folders].[folder_id], [SSISDB].[catalog].[packages].[f] or [SSISDB].[catalog].[projects].[f].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[f], [SSISDB].[catalog].[folders].[name], [SSISDB].[catalog].[packages].[f] or [SSISDB].[catalog].[projects].[f].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[j], [SSISDB].[catalog].[packages].[j], [SSISDB].[catalog].[projects].[j] or [SSISDB].[catalog].[projects].[name].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[p], [SSISDB].[catalog].[packages].[name], [SSISDB].[catalog].[packages].[p] or [SSISDB].[catalog].[projects].[p].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[f], [SSISDB].[catalog].[folders].[name], [SSISDB].[catalog].[packages].[f] or [SSISDB].[catalog].[projects].[f].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[j], [SSISDB].[catalog].[packages].[j], [SSISDB].[catalog].[projects].[j] or [SSISDB].[catalog].[projects].[name].
Error validating element [dbo].[ssisprojects]: View: [dbo].[ssisprojects] 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: [SSISDB].[catalog].[folders].[p], [SSISDB].[catalog].[packages].[name], [SSISDB].[catalog].[packages].[p] or [SSISDB].[catalog].[projects].[p].
Error validating element [dbo].[ssisprojects].[Folder]: Computed Column: [dbo].[ssisprojects].[Folder] 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: [SSISDB].[catalog].[folders].[f], [SSISDB].[catalog].[folders].[name], [SSISDB].[catalog].[packages].[f] or [SSISDB].[catalog].[projects].[f].
Error validating element [dbo].[ssisprojects].[Project]: Computed Column: [dbo].[ssisprojects].[Project] 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: [SSISDB].[catalog].[folders].[j], [SSISDB].[catalog].[packages].[j], [SSISDB].[catalog].[projects].[j] or [SSISDB].[catalog].[projects].[name].
Error validating element [dbo].[ssisprojects].[Package]: Computed Column: [dbo].[ssisprojects].[Package] 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: [SSISDB].[catalog].[folders].[p], [SSISDB].[catalog].[packages].[name], [SSISDB].[catalog].[packages].[p] or [SSISDB].[catalog].[projects].[p].
Extracting schema (Failed)

我应该在创建dacpac时关闭它吗?

0 个答案:

没有答案