【问题标题】:Error 71561: Unresolved reference to object错误 71561:未解析的对象引用
【发布时间】:2019-10-29 06:13:58
【问题描述】:

在 Visual Studio 2017、SSDT 2015 中,我收到“未解决的对象引用”错误。此错误发生了 2,589 次,因此它不是特定代码段的问题。所有代码都直接在 SQL Server 中编译和运行。

我已经尝试了 this 帖子中的所有内容,除了禁用“通用对象的扩展 Transact-SQL 验证”,因为该选项已被删除。

我已经尝试了几乎所有可以在 Google 上找到的其他内容;这两天我一直在努力解决这个问题。

下面是一些出现错误的代码示例。它直接在 SQL Server 上运行良好。错误出现在包含数据库引用的每一行的 FROM 子句中。我无法删除这些引用或更改视图的位置。这也发生在引用视图的存储过程中。

CREATE view [Migration].[vwCHILDS_Allegation_AllegationTrackingCharacteristics]
as
with src as (
    select
        (select AllegationId from CWNS_Migration.Allegation.Allegation where SourceSystemId = cast(1 as int) and SourceSystemIdentifier = cast(a.IDNBR as nvarchar(64))) AllegationId
        , (select TrackingCharacteristicsId from CWNS_Migration.Allegation.TrackingCharacteristics where Code = dfrvmi1.DestinationDataFieldReferenceValueCode) TrackingCharacteristicsId
        , (select VerificationStatusId from CWNS_Migration.Allegation.VerificationStatus where Code = dfrvmi2.DestinationDataFieldReferenceValueCode) VerificationStatusId
        , cast(1 as int) SourceSystemId
        , cast(src.IDNBR as nvarchar(64)) SourceSystemIdentifier
        , src.IDNBR SourceSystemIdentifier_Numeric
        , case when src.CRET_DT_TM = '0001-01-01' then null else src.CRET_DT_TM end SourceSystemCreatedDateTime
        , (
            select
                max(pe.PersonId) 
            from
                CWNS_Migration.PersonIdentity.PersonIdentifier pe
                join CHILDSDB2.VLCHA.STAFF_USERID st on cast(st.FK_STAFFFK_PERSID as nvarchar(64)) = pe.Identifier
                    and pe.PersonIdentificationSystemId = 4
            where
                st.USERID = ltrim(rtrim(src.CRET_USER_ID))) SourceSystemCreatedPersonId
    from
        CHILDSDB2.VLCHA.RPT_TRKNG_CHAR src
        join CHILDSDB2.VLCHA.ALGTN a on a.FK_RPTRPT_NBR = src.FK_RPTRPT_NBR
        join CHILDSDB2.VLCHA.FINDING f on f.FK_ALGTNID = a.IDNBR
        join DataCatalog.dbo.DataFieldReferenceValueMappingInfo dfrvmi1 on dfrvmi1.SourceDataFieldReferenceValueDataFieldId = 5438
            and dfrvmi1.SourceDataFieldReferenceValueCode = src.FK_TRKNG_CHAR_TCD
            and dfrvmi1.DestinationDataFieldReferenceValueDataFieldId = 20586
        join DataCatalog.dbo.DataFieldReferenceValueMappingInfo dfrvmi2 on dfrvmi1.SourceDataFieldReferenceValueDataFieldId = 1775
            and dfrvmi2.SourceDataFieldReferenceValueCode = f.FINDING_DET_CD
            and dfrvmi2.DestinationDataFieldReferenceValueDataFieldId = 55983
)
select
    src.*
from
    src
    left join CWNS_Migration.Allegation.AllegationTrackingCharacteristics tgt on tgt.SourceSystemId = src.SourceSystemId and tgt.SourceSystemIdentifier = src.SourceSystemIdentifier
    left join CWNS_Migration.Quarantine.AllegationTrackingCharacteristics q on q.SourceSystemId = src.SourceSystemId and q.SourceSystemIdentifier = src.SourceSystemIdentifier
        and q.QExecutionId = 1
where
    q.QExecutionId is null
    and (
        isnull(src.AllegationId, 0) <> isnull(tgt.AllegationId, 0)
        or isnull(src.TrackingCharacteristicsId, 0) <> isnull(tgt.TrackingCharacteristicsId, 0)
        or isnull(src.VerificationStatusId, 0) <> isnull(tgt.VerificationStatusId, 0)
        or try_cast(isnull(src.SourceSystemCreatedDateTime, '') as datetime) <> isnull(tgt.SourceSystemCreatedDateTime, '')
        or isnull(src.SourceSystemCreatedPersonId, '') <> isnull(tgt.SourceSystemCreatedPersonId, '')
    );

【问题讨论】:

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


    【解决方案1】:

    在您的项目中添加Database reference

    您需要重构代码才能使用:

    [$(*ReferencedDatabaseName*)].schemaName.tableName
    

    【讨论】:

    • 所以这可以消除大部分问题,但它并没有消除有关未解决的系统对象引用的警告。我在其他帖子中看到要解析对系统对象的引用,有必要添加对 Master 的引用。我已经这样做了,它解析了对同一数据库中系统对象的引用,但是如果你去跨数据库,它就不起作用了。
    • 看来您只是扩大了问题的范围。分享给您带来问题的部分脚本,让我们看看我们是否可以帮助您。
    猜你喜欢
    • 1970-01-01
    • 2021-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 2022-11-10
    • 2020-12-20
    相关资源
    最近更新 更多