0

I have the situation where I'm working in a new database, built using a Visual Studio 2012 database project.

I have two database projects. e.g. "DB1" and "DB2".

DB1 have synonyms of objects from DB2 and 
DB2 have synonyms of objects from DB1.

when I imported both database in two different dbproject. its throwing errors for the objects where the synonyms are used.

i got to know from blogs that one way to solve is add database project reference. but in that case i am getting into problem that

if I refer "DB1" in "DB2" then I cant refer "DB2" in "DB1".

any help would be highly appreciated.

MarmiK
  • 5,639
  • 6
  • 40
  • 49
Radhi
  • 6,289
  • 15
  • 47
  • 68
  • Did you read [Defining Cross-Database References](http://msdn.microsoft.com/en-us/library/bb386242.aspx#Cross-DatabaseReference) on MSDN – Pred Aug 06 '14 at 06:44
  • why use synonym in such way!? First refer why [synonyms](http://msdn.microsoft.com/en-us/library/ms187552.aspx) is used? and then use it in appropriate case only. Also one may refer [old post](http://stackoverflow.com/questions/1246006/what-is-the-use-of-synonym-in-sql-server-2008) – MarmiK Aug 06 '14 at 06:47
  • Marmik, that is in leagcy system which we cannot change currently. – Radhi Aug 06 '14 at 08:53
  • Pred, thanks for your post. it helped to explore blogs for my problems. and in the link sent by you it also talks about limitation of not able to add circular reference. – Radhi Aug 06 '14 at 08:53
  • I am having a similar problem in VS15 (2017). I have 4 DB projects. DB1 and DB2 use synonyms with the same name to point to a DB3 view. Works fine on the server, but the problem lies with Visual Studio not being able to interpret it. The DB1 synonym works in the stored procedures, but the DB2 view throws an error trying to reference the DB2 synonym. Changing a real world best practice to make VS happy seems rather like the tail wagging the dog does it not? – ARLibertarian Dec 30 '20 at 16:15

1 Answers1

0

found a blog where they said. there is no solution provided by microsoft for circular reference in dbproject.

The various workarounds suggested in MSDN forums far are far from ideal:

1) Creating a third DB project and include objects that require circular reference

2) Manage references using static .dbschema file

Source Blog

Radhi
  • 6,289
  • 15
  • 47
  • 68
  • Adding the DBSchema reference really isn't that cumbersome for most of these types of projects. If you're not building the DBs from nothing, you'll rarely see the issue. I'd highly recommend switching to SSDT over the older DB Projects if you can, though. Dacpac DB references take up less space and work a bit faster. – Peter Schott Aug 06 '14 at 17:19