Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't add database reference to VS2012 project

I have a SQL Server CLR trigger project that was created in VS2008. Opening the project in VS2012 does not present any problem, but on build of the solution, I get SQL71501 errors, with Trigger: [...] has an unresolved reference to object [...].

Based on my reading, this is due to a missing database reference in the project. When I try to add a database reference, I get the Add Database Reference dialog that gives me three options:

  • Database projects in the current solution ** this option is grayed out/disabled
  • System database (only shows system DBs)
  • Data-tier Application (.dacpac) ** there are no options to select as this was not how I created the project.

Further reading suggested that the reason there are no database projects to select for the first option, is because no Data Connections have been added via the Server Explorer. In my case there are certainly Data Connections present, and while my project is open, I can quite happily browse the database, look at data etc.

I thought it might have something to do with the Target Framework, so I have tried targeting 3.5 and even 2, but the same problem occurs.

I feel like I'm missing something fundamental, but just can't quite work it out. Any help would be GREATLY appreciated.

like image 525
user1564634 Avatar asked Jul 31 '12 05:07

user1564634


People also ask

How do you add references to a database?

In Solution Explorer, right click References and select Add Database Reference. Select the source of the database you are referencing (a project in the solution or a DACPAC). In the Add Database Reference dialog box, specify the Database Location as Same database. Copy the example usage and paste it into your .

How will you create a database project in Visual Studio 2019 from an existing database?

You can create a new project in visual studio and select 'SQL Server' in the left hand menu. Fill in the project name and location as usual. In your newly created database project, select Project, Import, Database. The import database window will open, set up your existing database in here and press start.


2 Answers

I've seen this dialog not enable the 'OK' button because the Database Variable that it defaults is invalid (in my case it had a '.' in it).

The clue to this being the error is that the text in the 'Example Usage' field contains the error message - it's just hard to see as it's dark grey on light grey.

Editing the Database Variable name fixes this.

like image 198
David Gardiner Avatar answered Oct 22 '22 18:10

David Gardiner


I found a workarroud for this, isn't optimal but at least it works:

try this - open sql server object explorer - create a new connection to your server - right click on the database and select create new the project... - the wizard will create the project with all the references and connection string attached to it.

cheers!

like image 41
pedrommuller Avatar answered Oct 22 '22 19:10

pedrommuller