简体   繁体   English

VS2010 数据库项目(SQL Server 2008)中的 SQL03006 错误

[英]SQL03006 error in VS2010 Database Project (SQL Server 2008)

When I try to set up a database project for SQL Server 2008 in VS2010 I keep running into error "SQL03006 - Column xyz 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..." When I try to set up a database project for SQL Server 2008 in VS2010 I keep running into error "SQL03006 - Column xyz contains an unresolved reference to an object. Either the object does not exist or the reference is ambiguous because it could refer to any以下对象..."

One example with the original code would be as follows:原始代码的一个示例如下:

CREATE VIEW [dbo].[vwSomeView]
AS
SELECT 
    CT.ID, 
    CT.UserName, 
    ST.Title
FROM
    SomeOtherDatabase.dbo.ComputerTable CT
JOIN
    SomeOtherDatabase.dbo.SoftwareTable ST ON
    CT.ID = ST.ComputerID

Now the error only refers to eg column CT.UserName, not CT.ID.现在错误仅涉及例如列 CT.UserName,而不是 CT.ID。 I also added a corresponding database reference to "SomeOtherDatabase" and updated the code as recommended by several posts I found during my search for a solution:我还添加了对“SomeOtherDatabase”的相应数据库引用,并按照我在寻找解决方案时发现的几篇文章的建议更新了代码:

CREATE VIEW [dbo].[vwSomeView]
AS
SELECT 
    CT.ID, 
    CT.UserName, 
    ST.Title
FROM
    [$(SomeOtherDatabaseName)].dbo.ComputerTable CT
JOIN
    [$(SomeOtherDatabaseName)].dbo.SoftwareTable ST ON
    CT.ID = ST.ComputerID

What I don't understand is why there is a problem with one column from the CT table, but not the other.我不明白为什么 CT 表中的一列有问题,而另一列却没有。 When I look at the table definition in the database project, all seems to be fine as the column is there (as expected).当我查看数据库项目中的表定义时,一切似乎都很好,因为列在那里(如预期的那样)。

I'm also not quite sure whether I can refer to the table names by their alias once that is defined, ie do I have a problem writing "CT.ComputerID" instead of "[$(SomeOtherDatabaseName)].dbo.ComputerTable" (I don't think so, but I keep running into so many errors that I feel a little bit lost at the moment).我也不太确定是否可以在定义后通过别名来引用表名,即我在编写“CT.ComputerID”而不是“[$(SomeOtherDatabaseName)].dbo.ComputerTable”时遇到问题(我不这么认为,但我一直遇到很多错误,以至于我现在感觉有点失落)。

Any pointers in the right direction are appreciated, thank you.感谢您提供正确方向的任何指示,谢谢。

Update更新

The actual error message is like:实际的错误信息如下:

SQL03006: View: [dbo].[vwSomeView] 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: [$(SomeOtherDatabaseName)].[dbo].[ComputerTable]::[ID] or [$(SomeOtherDatabaseName)].[dbo].[SoftwareTable]::[ID]"

G. G。

The JOIN is SoftwareTable.ComputerID to on ComputerTable.ID which implies to me that there is no ComputerID column in ComputerTable (the CT alias) JOIN 是ComputerTable.ID上的SoftwareTable.ComputerID ,这对我来说意味着ComputerTable中没有ComputerID列(CT 别名)

Do you really have a ComputerTable.ComputerID column in addition to ComputerTable.ID ?除了ComputerTable.ID之外,您真的有一个ComputerTable.ComputerID列吗? Which is the unique key for the foriegn key on SoftwareTable ? SoftwareTable上的外键的唯一键是哪个?

The [$(SomeOtherDatabaseName)] bit is a red herring I think [$(SomeOtherDatabaseName)]位是我认为的红鲱鱼

Edit:编辑:

Your error is caused by SQL Server looking for a database name [$(SomeOtherDatabaseName)]您的错误是由 SQL 服务器查找数据库名称[$(SomeOtherDatabaseName)]引起的

It isn't being corrcted by VS for some reason.出于某种原因,它没有被 VS 纠正。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM