6

I created a new SQL Server Database Project within VS 2010, imported the database objects and settings from a local database named "managers", and received the following error while attempting to build the project:

SQL03006: View: [dbo].[vw_mlFunds] has an unresolved reference to object [managers].[dbo].[mlfunds].

I don't know why this view is fully qualifying a table reference to include the actual database name and I would prefer not to have to change the sql, as it someone else's code and it technically is not incorrect. But I am thinking that fully qualifying the table name to include the name of the database is confusing the VS compiler, since it is expecting [dbo].[mlfunds], not [managers].[dbo].[mlfunds]. How best to resolve this issue? Can I set up a new database name variable/alias somewhere? Or will I have to refactor/modify the sql to get it to compile? Thanks in advance.

3 Answers 3

5

Actually, it looks like the code will have to be modified, as this is not supported. Answer found in this post:

Using local 3-part names in programmability objects

1
  • If you hook this up and can't figure why your your comparison scripts are still bombing, make sure to set the "SQLCMD Variables" option in the initial "Select Source/Target Schema" screen.
    – chprpipr
    Commented Nov 18, 2010 at 22:54
2

I was getting the same error after creating a project and importing a DB. The issue for me was that the FROM table reference included the fully qualified name, but the selected fields did not; as follows

SELEC l.UserID, l.Email, m.DOB, ...
FROM ***[DBName].dbo***.Layout as l
LEFT OUTER JOIN masterUs as m

I modified the fully qualified reference by removing the DBName and DBO portion and all errors were resolved

SELECT l.UserID, l.Email, m.DOB, ....
FROM Layout as l
LEFT OUTER JOIN masterUs as m
1

You need to create another database project for the [managers] database and have your project 'reference' the other project. You can do this as a simple reverse-engineer step on the [managers] database that will import all the objects in that database into a new VSDB project. See Using References in Database Projects.

3
  • Could you clarify this for me? I'm confused by the need for a reference when both objects (the base table and the view) reside in the same [managers] database. Commented Aug 23, 2010 at 21:29
  • 1
    I thought [managed] is a different database. IF the view qualifies explicitly the table name with the database name then the view definition is technically incorrect, because the project can be deployed under a different DB name, and even post-deployment it can be restored/copied/attached/snapshot under a variety of names and the view would be invalid in all those scenarios. Commented Aug 23, 2010 at 22:13
  • I think fully qualifying the table with the database name was unintentional on the part of the original developer, and we may end up modifying the view script to remove the database name reference, but the create script for the view will run as-is without errors in ssms and, when run against the managers database, it will recognize the explicit reference to managers as being to itself. I agree this is sloppy code but was trying not to mess with it for the moment, as it will require testing. That is why I was trying to figure out if there is some way around this. Commented Aug 25, 2010 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.