简体   繁体   English

无法向VS2012项目添加数据库引用

[英]Can't add database reference to VS2012 project

I have a SQL Server CLR trigger project that was created in VS2008. 我有一个在VS2008中创建的SQL Server CLR触发器项目。 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 [...]. 在VS2012中打开项目没有任何问题,但是在构建解决方案时,我得到SQL71501错误,使用Trigger:[...]有一个未解析的对象引用[...]。

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) 系统数据库(仅显示系统DB)
  • Data-tier Application (.dacpac) ** there are no options to select as this was not how I created the project. 数据层应用程序(.dacpac)**没有选项可供选择,因为这不是我创建项目的方式。

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. 我认为这可能与目标框架有关,所以我尝试过针对3.5甚至2,但同样的问题也出现了。

I feel like I'm missing something fundamental, but just can't quite work it out. 我觉得我缺少一些基本的东西,但是不能完全解决它。 Any help would be GREATLY appreciated. 任何帮助将不胜感激。

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). 我看到这个对话框没有启用'OK'按钮,因为它默认的数据库变量是无效的(在我的情况下,它有一个'。')。

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. 编辑数据库变量名称修复此问题。

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. 试试这个 - 打开sql server object explorer - 创建一个到服务器的新连接 - 右键单击​​数据库并选择create new the project ... - 向导将创建项目,其中包含所有引用和连接字符串。

cheers! 干杯!

I changed my answer 我改变了答案

The problem is you cannot assume an insert is a single row and you can really only reference the primary key as a single value inside the trigger 问题是您不能假设插入是单行,您实际上只能将主键作为触发器内的单个值引用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM