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..."
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. 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:
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. 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).
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.
The JOIN is SoftwareTable.ComputerID
to on ComputerTable.ID
which implies to me that there is no ComputerID
column in ComputerTable
(the CT alias)
Do you really have a ComputerTable.ComputerID
column in addition to ComputerTable.ID
? Which is the unique key for the foriegn key on SoftwareTable
?
The [$(SomeOtherDatabaseName)]
bit is a red herring I think
Edit:
Your error is caused by SQL Server looking for a database name [$(SomeOtherDatabaseName)]
It isn't being corrcted by VS for some reason.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.