Database references for system objects

A database project configured in Visual Studio will have database references to external and internal databases it requires. While I would strongly advise against crossing database boundaries using this mechanism, there are legacy systems that require this. Part of bringing those legacy databases into standard development and deployment patterns means setting up database projects and publish profiles.

For your own databases that is a trivial task, but what do you do when using the system metdata. Examples of these areĀ sys.objects, sys. tables and more. These objects raise errors in the pattern “Object 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”. Fortunately these are easy to resolve.The short answer is you need a reference to the master database.

  1. Right click on References in your database project and select “Add Database Reference”.
  2. Under Database Reference select the “System database” radio button.
  3. Select “master” from the drop down list.
  4. Click “OK”

When you do this the database will show under References as per the below.

database references

Moreover, all your errors relating to this should have disappeared.