115

I've created a UDF that accesses the [INFORMATION_SCHEMA].[TABLES] view:

CREATE FUNCTION [dbo].[CountTables]
(
    @name sysname
)
RETURNS INT
AS
BEGIN
    RETURN
    (
        SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @name
    );
END

Within Visual Studio, the schema and name for the view are both marked with a warning:

SQL71502: Function: [dbo].[CountTables] has an unresolved reference to object [INFORMATION_SCHEMA].[TABLES].

I can still publish the database project without any problems, and the UDF does seem to run correctly. IntelliSense populates the name of the view for me, so it doesn't seem to have a problem with it.

I also tried changing the implementation to use sys.objects instead of this view, but I was given the same warning for this view as well.

How can I resolve this warning?

4

4 回答 4

208

将数据库引用添加到master

  1. 在项目下,右键单击References
  2. 选择添加数据库引用...。
  3. 选择系统数据库
  4. 确保选择了主人
  5. 确定

请注意,VS 更新可能需要一段时间。

于 2013-08-07T06:59:33.077 回答
4

在我们的项目中,我们已经有对 master 的引用,但是我们遇到了这个问题。这是我们得到的错误:

SQL71502: Procedure: [Schema].[StoredProc1] has an unresolved reference to object [Schema].[Table1].[Property1].

要解决引用错误,请在表 sql 文件上,右键单击属性并验证 BuildSettings 是否设置为 Build。

更改它构建修复它。

于 2016-12-15T17:47:49.773 回答
3

山姆所说的是做到这一点的最佳方式。
但是,如果您有需要从在该特定位置没有该引用的机器部署 dacpac 的场景,您可能会遇到麻烦。另一种方法是打开您的 .project 文件并确保以下标记具有false您尝试运行的构建配置的值。

<TreatTSqlWarningsAsErrors>false</TreatTSqlWarningsAsErrors>

这样您就不需要添加对项目的引用。

于 2014-01-27T20:05:29.287 回答
0

我正在使用 VS 2019,即使在添加主数据库引用后仍然遇到此问题。通过更改数据库项目的目标平台解决了这个问题,如下图所示。在此更改后,我不得不再次删除并重新添加主数据库。 在此处输入图像描述

于 2021-10-07T08:39:51.617 回答