SQL Source Control 6

Failed to locate the [object name] for the [object name]

This error is shown when you unlink a database, edit objects that reference other objects, and then relink the database. When SQL Source Control rebuilds the working base, it generates invalid SQL because the referenced objects have changed.

For more information about the working base, see How SQL Source Control works behind the scenes

Fix

To fix the problem, you need to make the database and source control versions of the referenced objects the same.

There are several ways to do this, depending on whether you want to take the version of the object in source control or the version in the database.

To take the version in the database

Manually edit the SQL scripts in the source control repository to match the database.

  1. Open your source control repository. You can find the repository location on the Setup tab in SQL Source Control.
  2. Find the SQL files for the affected objects, edit the files so they match the objects in the database, and save the changes.
  3. In SQL Source Control, unlink the database and link it to source control again.

Other developers linked to the repository will see the changes on the Get latest tab.

To take the version in source control

If you have SQL Compare Pro

You can use SQL Compare Pro to deploy the SQL scripts in the SQL Source Control transient to the database. The transient is a copy of the version in source control (see How SQL Source Control works behind the scenes).

To do this:

  1. In Management Studio, make sure you have the affected database selected in the Object Explorer.
  2. In SQL Source Control, on the Setup tab, expand Under the hood and click Open transient.
    The transient opens in Windows Explorer. 
  3. Copy the transient location (eg C:\Users\username\AppData\Local\Red Gate\SQL Source Control 4\Transients\q4jmm33z.btr).
  4. In SQL Compare, open a new project.
  5. On the left, under Source, select Source Control.
  6. Under Source Control, select Scripts folder, and in the Scripts folder field, paste the transient folder location from step 2.
  7. On the right, under Target, enter the connection details for affected database.
  8. Click Compare Now, and when the comparison completes, click OK.
  9. In the list of objects, select the affected objects and click Deployment Wizard.
  10. In the Deployment Wizard, on the left, select Deploy using SQL Compare and click Next.
  11. Click Deploy Now.
  12. In SQL Source Control, unlink the database and link it to source control again.

If you don't have SQL Compare Pro

Manually edit the database to match the SQL scripts in the source control repository.

To do this:

  1. Open your source control repository. You can find the repository location on the Setup tab. 
  2. Find the SQL files for the affected objects.
  3. Edit the objects in the database to match the SQL files in the source control repository.
  4. In SQL Source Control, unlink the database and link it to source control again.
If that didn't work

Remove the references and stop SQL Source Control generating invalid SQL. 

This method might require deleting tables from the database.

To do this:

  1. In Management Studio, remove the references from the affected objects.
  2. Unlink the database and link it to source control again.
  3. Go to the Get latest tab, select the affected objects, and click Get latest.
  4. Re-add the references.

Didn't find what you were looking for?