database 抑制 Visual Studio 2010 中的数据库项目错误和警告
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5685139/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Suppress Database Project errors and warnings in visual studio 2010
提问by Sumit
I have an Database project in my application and want to suppress the errors/warnings thrown by this project. .first of all is it possible ?
我的应用程序中有一个数据库项目,并希望抑制该项目引发的错误/警告。.首先有可能吗?
I think I was not clear with my question, by suppressing I meant that when I build my Solution, the errors(which actually are not errors) are shown in the error list, I just want that all Database project related errors should not be shown in the error list.
我想我不清楚我的问题,通过抑制我的意思是当我构建我的解决方案时,错误(实际上不是错误)显示在错误列表中,我只是希望不应该显示所有与数据库项目相关的错误在错误列表中。
I am using VS2010.
我正在使用 VS2010。
thanks in advance
提前致谢
回答by Rushui Guan
To surppress a specific warning, go to project properties -> Build.
要抑制特定警告,请转到项目属性 -> 构建。
Type in the warning numbers in comma delimited format in field "Suppress Transact-SQL warnings:".
在字段“禁止 Transact-SQL 警告:”中以逗号分隔格式键入警告编号。
回答by Ricardo Figueiredo
What i tried and worked for me was select the file in the project: i.e.: projectDatabase\ddl\table_name.sql and on the file properties window set Build Action : None.
我尝试并对我来说有效的是选择项目中的文件:即:projectDatabase\ddl\table_name.sql 并在文件属性窗口设置构建操作:无。
In build it doesn't look in this files for errors or warnings.
在构建中,它不会在此文件中查找错误或警告。
Little late but hope that help.
有点晚了,但希望有所帮助。
回答by Mark Worrall
Just had this problem in Visual Studio 2015.
刚刚在 Visual Studio 2015 中遇到了这个问题。
Halfway along the header of the Error List panel, there is a (unnamed) dropdown with values 'Build + Intellisense', 'Build Only', 'Intellisense Only'. Mine was set to 'Build + Intellisense'. Changing it to 'Build Only' got rid of all the (200+) errors.
在错误列表面板标题的中间,有一个(未命名的)下拉列表,其值为“Build + Intellisense”、“Build Only”、“Intellisense Only”。我的设置为“构建+智能感知”。将其更改为“仅构建”消除了所有(200 多个)错误。
回答by Jaguar
better late than never:
迟到总比不到好:
Options -> Database Tools -> Databse Errors and Warnings -> set the maximum at 0 and from now on the error window will have a single entry that will say something like
选项 -> 数据库工具 -> 数据库错误和警告 -> 将最大值设置为 0,从现在开始错误窗口将有一个条目,内容如下
Error 1 The maximum number of 0 errors has been reached. 76 total errors, 0 total warnings, and 0 total messages were encountered.
错误 1 已达到 0 错误的最大数量。共遇到 76 个错误、0 个总警告和 0 个总消息。
--EDIT-- FROM THE COMMENT BELOW...VERY HELPFUL
In VS 11 it appears this option has moved to Tools > Options > SQL Server Tools > General
--编辑--来自下面的评论......非常有帮助
在VS 11中,此选项似乎已移至“工具”>“选项”>“SQL Server工具”>“常规”
回答by Richard
You could remove the build/deploy of the project from your solution configuration. That way VS would not try to build the database project at all.
您可以从解决方案配置中删除项目的构建/部署。这样 VS 根本不会尝试构建数据库项目。
Of course any changes in the database project would be ignored.
当然,数据库项目中的任何更改都将被忽略。
To change or create a new solution file right click on the solution node in Solution Explorer and select properties. In that dialogue the configuration node (under Configuration Properties) tab and click configuration manager.
要更改或创建新的解决方案文件,请右键单击解决方案资源管理器中的解决方案节点并选择属性。在该对话框中,配置节点(在配置属性下)选项卡并单击配置管理器。
This allows you create new configurations and edit existing ones, and each configuration is mapped on to a project configuration (to add a new one select <new>on the active solution drop down).
这允许您创建新配置并编辑现有配置,并且每个配置都映射到一个项目配置(<new>在活动解决方案下拉列表中选择添加一个新配置)。
Of course, the better approach is to fix the errors.
当然,更好的方法是修复错误。
回答by dave
My workaround (in VS2019) was:
我的解决方法(在 VS2019 中)是:
1) Set Build Action to None for this script. => To avoid error messages 2) Create a PostDeployment script (if not present) 3) Add the line :r .\Path_script\script_name.sql => To execute the script when publishing (Add a drop statement before if necessary)
1) 将此脚本的构建操作设置为无。=> 避免错误消息 2) 创建一个 PostDeployment 脚本(如果不存在) 3) 添加行 :r .\Path_script\script_name.sql => 在发布时执行脚本(如果需要,在之前添加一个 drop 语句)
Activate SQLCMD Mode in menu SQL->Execution settings -> SQLCMD Mode
在菜单 SQL->Execution settings -> SQLCMD Mode 中激活 SQLCMD Mode
Hope this help.
希望这有帮助。
回答by Hector Diaz Contreras
Going back to the accepted answer for Warnings and Visual Studio 2019:
回到警告和 Visual Studio 2019 的公认答案:
1) Right click on the database project and select properties Database solution
1) 右键单击数据库项目并选择属性 数据库解决方案
2) Under "Build" and "Suppress Transact-SQL warnings:" enter the SQL warning number you want to suppress, ex: SQL71502 you enter 71502. You can enter multiple warning suppression codes in a coma delimiter way. Example of suppression codes for unresolved reference to object
2) 在“Build”和“Suppress Transact-SQL warnings:”下输入要抑制的SQL警告编号,例如:SQL71502,您输入71502。您可以以逗号分隔符的方式输入多个警告抑制代码。 未解析对象引用的抑制代码示例
3) Save your solution and warning should go away. You might have multiple warning codes to enter in order for the warnings to 0 out.
3) 保存您的解决方案,警告应该会消失。您可能需要输入多个警告代码才能将警告设为 0。
回答by CodingYoshi
In VS 2015, you can suppress the warning 2 ways.
在 VS 2015 中,您可以通过 2 种方式抑制警告。
Project Level
项目级别
I don't suggest this because I only like suppressing warnings if I know exactly what I am suppressing. In C#, for example, we can use SuppressMessageAttributeat a very granular level.
我不建议这样做,因为我只喜欢在我确切地知道我在压制什么的情况下压制警告。例如,在 C# 中,我们可以在非常精细的级别使用SuppressMessageAttribute。
Nonetheless, here is how:
尽管如此,方法如下:
Right click database project > Properties > Build > Suppress Transact-SQL Warnings:
右键单击数据库项目 > 属性 > 构建 > 抑制 Transact-SQL 警告:
Enter the warnings you want to suppress such as 4151.
输入要禁止的警告,例如 4151。
File Level
文件级别
I prefer/suggest this option because it is more granular compared to above option.
我更喜欢/建议此选项,因为与上述选项相比,它更精细。
Right click file in solution explorer1> Properties > Suppress T-SQL Warnings
在解决方案资源管理器1 中右键单击文件> 属性 > 禁止 T-SQL 警告
Enter the warnings you want to suppress such as 4151.
输入要禁止的警告,例如 4151。
1. You must right click the file node in solution explorer. You will get a different options if you right click the file in editor.
1. 您必须在解决方案资源管理器中右键单击文件节点。如果您在编辑器中右键单击文件,您将获得不同的选项。
There may exist another way but I only know of these 2 ways thus far.
可能存在另一种方式,但到目前为止我只知道这两种方式。
回答by Sujeet
In Visual studio 2017, you can do the following: Go to tools --> options --> SQL server tools --> Under Errors & Warnings, set “Maximum no. of errors & warnings….” as 1.
在 Visual Studio 2017 中,您可以执行以下操作:转到工具 --> 选项 --> SQL 服务器工具 --> 在错误和警告下,设置“最大数量”。错误和警告……” 作为 1。
回答by aWebdesigner09
You may Exclude that project while build by right click on that project and choose 'Exclude Project'if Windows App. 'Unload Project' if Web App.
To show/Hide Error list
Go to Tools > Options
Expand Projects and Solutions
Choose General.
On the right hand side, First check box is 'Always show Error List if build finishes with errors'
您可以在构建时通过右键单击该项目并在 Windows 应用程序中选择“排除项目”来排除该项目。如果是 Web 应用程序,则为“卸载项目”。
显示/隐藏错误列表
转到工具 > 选项
扩展项目和解决方案
选择通用。
在右侧,第一个复选框是“如果构建完成时出现错误,则始终显示错误列表”

