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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13373310/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:46:34  来源:igfitidea点击:

VS 2012 Database Project "unresolved reference to object" Error

databasevisual-studio-2012sql-server-data-tools

提问by Adel Khayata

I created SQL Server Database Project in VS 2012 & imported our database. When I build the project, I get a lot of "unresolved reference to object" Errors. These errors are only for a few views I have in my database. The syntax for these views are correct & I am not using temp tables. What should I check to solve this issue?

我在 VS 2012 中创建了 SQL Server 数据库项目并导入了我们的数据库。当我构建项目时,我收到很多“未解析的对象引用”错误。这些错误仅适用于我的数据库中的一些视图。这些视图的语法是正确的,我没有使用临时表。我应该检查什么来解决这个问题?

UPDATE: This is one example:

更新:这是一个例子:

    CREATE view [Factory].[NonStartedOrders]
as
 SELECT 

"Customers"."CustomerName", "Customers"."CustomerAName",
"Customers"."MarketID",
"Orders"."OrderID", 
"Orders"."ApproveDate", 
"FactoryOrders"."FactoryID", 
"FactoryOrders"."EstEndDate", 
"FactoryOrders"."StatusID", 
"FactoryOrders"."TotalWeight", 
"Karats"."KaratEName"

FROM   (("Taiba"."Sales"."FactoryOrders" "FactoryOrders" 
INNER JOIN "Taiba"."Sales"."Orders" "Orders" ON "FactoryOrders"."OrderID"="Orders"."OrderID") 
INNER JOIN "Taiba"."General"."Customers" "Customers" ON "Orders"."CustomerID"="Customers"."CustomerID") 
INNER JOIN "Taiba"."MasterPiece"."Karats" "Karats" ON "Orders"."MKaratID"="Karats"."KaratID"

"Taiba" here is my database name. I am getting 30 errors only for this view. These are a few errors of them:

“Taiba”这里是我的数据库名称。我仅针对此视图收到 30 个错误。这是他们的一些错误:

Error   217 SQL71561: View: [Factory].[NonStartedOrders] has an unresolved reference to object [Taiba].[Sales].[FactoryOrders]

Error   219 SQL71561: View: [Factory].[NonStartedOrders] 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: [Taiba].[Sales].[FactoryOrders].[FactoryOrders]::[OrderID], [Taiba].[Sales].[FactoryOrders].[OrderID] or [Taiba].[Sales].[Orders].[FactoryOrders]::[OrderID].

采纳答案by Adel Khayata

I solved this issue.

我解决了这个问题。

It seems a few of my views/SPs has referenced the tables using this naming convention ( 3 parts qualified name ):

似乎我的一些视图/SP 使用此命名约定(3 部分限定名称)引用了表:

DatabaseName.SchemaName.TableName

数据库名称.架构名称.表名称

I changed all references to be as the following:

我将所有引用更改为如下:

SchemaName.TableName

架构名.表名

回答by Gwasshoppa

One other possibility is that the schema you have used in your view/table etc does not exist in the project. You may need to add the schema to the VS Database Project.

另一种可能性是您在视图/表等中使用的架构在项目中不存在。您可能需要将架构添加到 VS 数据库项目。

Right Click the project and Add > New Item > Schema

右键单击项目并 Add > New Item > Schema

回答by fiat

In my case, the function that couldn't be found was of Build Action=Noneand so it wasn't being included in the compile.

就我而言,找不到的函数是 Build Action= None,因此它没有包含在编译中。

Changing the Build Action to Buildcorrected this.

将构建操作更改为构建更正了这一点。

回答by ClarenceG

This happened to me when building a CTE in Visual Studio 2015. I changed the Build Action to Compile and the errors went away.

这发生在我在 Visual Studio 2015 中构建 CTE 时。我将构建操作更改为编译,错误消失了。

  1. Select the file(s) with the error
  2. Press F4 to see the properties.
  3. Select 'Compile' in the Build Action drop down list.
  1. 选择有错误的文件
  2. 按 F4 查看属性。
  3. 在构建操作下拉列表中选择“编译”。

Hope this helps someone.

希望这可以帮助某人。

回答by Nilanjan Pal

It is possible that the objects are inside NotInBuildtag in the project file for naming or other issue. In my case I saved the file with ..sql and the extra dot was causing it to move under NotInBuild tag inside project file. I corrected the extension and moved the missing object under build tag and that resolved the issue.

对象可能位于项目文件中的NotInBuild标记内,用于命名或其他问题。在我的例子中,我用 ..sql 保存了文件,额外的点导致它在项目文件内的 NotInBuild 标记下移动。我更正了扩展并将丢失的对象移动到构建标记下,从而解决了问题。

回答by Sorensen

To reference another sqlproj's schema and use three-part naming, modify your .sqlproj file to add a DatabaseVariableLiteralValueelement on the referenced project.

要引用另一个 sqlproj 的架构并使用三部分命名,请修改 .sqlproj 文件以DatabaseVariableLiteralValue在引用的项目上添加一个元素。

In within the element like <ProjectReference Include="..\SomeDatabaseProject\SomeDatabaseProject.sqlproj">, add the following:

在元素 like 中 <ProjectReference Include="..\SomeDatabaseProject\SomeDatabaseProject.sqlproj">,添加以下内容:

<DatabaseVariableLiteralValue>SomeDatabaseProject</DatabaseVariableLiteralValue>

<DatabaseVariableLiteralValue>SomeDatabaseProject</DatabaseVariableLiteralValue>

For example:

例如:

    <ProjectReference Include="..\SomeDatabaseProject\SomeDatabaseProject.sqlproj">
      <Name>SomeDatabaseProject</Name>
      <Project>{some-project-guid}</Project>
      <Private>True</Private>
      <DatabaseVariableLiteralValue>SomeDatabaseProject</DatabaseVariableLiteralValue>
    </ProjectReference>

Then you can use clean, three-part naming references like SomeDatabaseProject.SomeSchema.SomeTable.

然后你可以使用干净的、由三部分组成的命名引用,比如SomeDatabaseProject.SomeSchema.SomeTable.

回答by Fetchez la vache

This may be an edge case but if in your object definition you are also documenting the object (we do, anyway...) using sp_addextendedproperty you can also get this error if you have stated an incorrect object type - which can happen if copy & pasting. The "unresolved reference to object" error makes sense here when you think about it.

这可能是一个边缘情况,但如果在您的对象定义中您还使用 sp_addextendedproperty 记录对象(无论如何我们都这样做...),如果您声明了不正确的对象类型,您也可能会收到此错误 - 如果复制 &粘贴。当您考虑它时,“未解析的对象引用”错误在这里很有意义。

For example the following will recreate the error as the level1type should be 'PROCEDURE' and not 'FUNCTION'.

例如,以下将重新创建错误,因为 level1type 应该是“PROCEDURE”而不是“FUNCTION”。

EXEC sp_addextendedproperty
  @name = N'MS_Description',
  @value = N'Description of the stored procedure...',
  @level0type = N'SCHEMA',
  @level0name = N'dbo',
  @level1type = FUNCTION',
  @level1name = N'spMyStoredProcedureName'
GO

回答by Dev

You will also get this error when you add a table (using .sql file ) and if you do not check-in the .sqlproj file

当您添加表(使用 .sql 文件)并且不签入 .sqlproj 文件时,您也会收到此错误

回答by superlogical

Try explicitly defining the class:

尝试明确定义类:

class:Specifies the class of the securable on which the permission is being granted. The scope qualifier :: is required.

class:指定授予权限的安全对象的类。范围限定符 :: 是必需的。

Read the docs on the SQL GRANTstatement: http://technet.microsoft.com/en-us/library/ms187965.aspx

阅读有关 SQLGRANT语句的文档:http: //technet.microsoft.com/en-us/library/ms187965.aspx

In my case I had a User Defined Table Type.

就我而言,我有一个用户定义的表类型。

GRANT EXECUTE ON TYPE::[dbo].[MessageTableType] TO [PostOffice_Role];