51

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.

thanks in advance

Sumit
  • 2,932
  • 6
  • 32
  • 54
  • 1
    I've been struggling with this same problem. After creating a new VS2010 SQL-2008 Database Project, importing "Database Objects and Settings", and then attempting to build the project, I receive a ton of compilation errors. All of these errors are relatively the same, **"SQL3006: User: [X] has an unresolved reference to Login [X]"**. I've also tried adding the local msdb.schema and master.schema references to the project. But, to no avail :(. – Buffalo May 17 '11 at 23:19
  • 3
    you could exclude database project from the build actions of the solution, once I did that my database project error(which in real are not errors ) were converted into warnings and I was able to work properly, but still the thing is whenever there was actual error in the solutions, then all the database warnings were converted into errors and I had a lot of problems in finding the actual error, I am still looking for a way so that all database project warnings are not shown in either of the windows(error and warning window). Will post if I find any solution – Sumit May 18 '11 at 04:20
  • To all answered suggestions.. Of course he wants to build and see the changes in the result afterwards. And while I'm ranting, why do I see serveral almost identical answers? You lot just loves to read your own name on the internet, huh? – Christian Nov 19 '18 at 10:48
  • be sure and review https://stackoverflow.com/a/43321023/607701. it solves the problem even though it doesn't have as many votes. – David Peden Apr 27 '20 at 15:41

11 Answers11

66

To surppress a specific warning, go to project properties -> Build.

Type in the warning numbers (i.e. without 'SQL') in comma delimited format in field "Suppress Transact-SQL warnings:".

Marcus Gambit
  • 180
  • 1
  • 9
Rushui Guan
  • 3,023
  • 1
  • 24
  • 26
  • 48
    _without_ the SQL prefix. To suppress SQL04151, just enter 04151 – Matt Stephenson Nov 12 '12 at 21:13
  • 11
    Are you claiming that this actually suppresses the errors as well, because it didn't for me... Am I doing something wrong? – user1431072 Feb 15 '14 at 01:34
  • 1
    I wouldn't think you can suppress an error. It should be resolved. – Rushui Guan Mar 01 '14 at 03:26
  • 2
    I also had to close and re-open the solution in order to clear out the warnings. – carmbrester Jul 27 '15 at 13:04
  • 1
    This isn't working for me - First off there is no "Suppress Transact-SQL Warnings" box, but there is just a "Suppress warnings" That doesn't suppress the SQL errors, though. – Sean Worle Dec 19 '18 at 19:04
  • @RushuiGuan - In our case, we have SQL code for Sybase ASE, which does not always match Transact-SQL syntax. So we are getting a lot of errors from Visual Studio that are not, in fact, actually errors. For example, Visual Studio doesn't understand the syntax "At ISOLATION LEVEL 0". – Sean Worle Dec 19 '18 at 19:07
  • Does anybody know if there's a way to do this on a per-file basis? Like a PRAGMA in directive? – Pxtl Jan 11 '19 at 00:56
47

Select the file in the project:

example: projectDatabase\ddl\table_name.sql

on the Properties Window of the file set

Build Action : None.

While building it doesn't look in this files for errors or warnings.

Ricardo Figueiredo
  • 1,416
  • 13
  • 10
  • 4
    This is the correct answer regarding suppression of the build errors. This is extremely helpful when database project is used for nothing but source control and MS should have known better and included an option not to include entire DB projects into the solution build. Building a small web site and seeing how it generates 10,000 errors re DB, than going in and changing each SQL file's build option from `Build` to `Not in build` is nightmarish. – ajeh Jan 29 '15 at 15:43
  • 4
    This also has the peculiar side effect of removing the project file from the sql schema comparison. After setting vw_MyView to build action "none", the sql schema compare *always* thinks this is a new file (even though it is already in the project). Frustrating!!! – Robert Altman Jan 18 '17 at 19:12
  • 1
    @RobertAltman I had the same problem, so I tried instead the solution by Richard below, that that worked without messing up schema compare (VS2017). – 8forty Aug 02 '18 at 22:08
19

Just had this problem in 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.

Mark Worrall
  • 290
  • 3
  • 9
13

Updated answer

In VS 11+ the option has moved to Tools > Options > SQL Server Tools > General -> Errors and Warnings (set to 0 to get get a single error line)

You can exclude the project from the build configuration to avoid build failure.

For older versions

Options -> Database Tools -> Database 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

Error 1 The maximum number of 0 errors has been reached. 76 total errors, 0 total warnings, and 0 total messages were encountered.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
Jaguar
  • 5,929
  • 34
  • 48
6

In VS 2015, you can suppress the warning 2 ways.

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 SuppressMessageAttribute at a very granular level.

Nonetheless, here is how:

Right click database project > Properties > Build > Suppress Transact-SQL Warnings:

Enter the warnings you want to suppress such as 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

Enter the warnings you want to suppress such as 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.

There may exist another way but I only know of these 2 ways thus far.

CodingYoshi
  • 25,467
  • 4
  • 62
  • 64
  • the most helpful answer at the moment, as it is the only answer that describes suppression on the file level – aluky Jun 08 '20 at 11:37
4

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.

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).

Of course, the better approach is to fix the errors.

Richard
  • 106,783
  • 21
  • 203
  • 265
  • i have already removed build/deploy option from the solution. – Sumit Apr 16 '11 at 07:40
  • How is "hide errors" in practice any different to "don't build"? – Richard Apr 16 '11 at 07:43
  • I am not aware of "hide errors" option , can u elaborate more. – Sumit Apr 16 '11 at 07:45
  • @Sumit: I'll re-phrase: How would a "hide errors" option be any different to "don't build" in practice? – Richard Apr 16 '11 at 07:49
  • @Richard: the thing is "dont build" option is not hiding the errors, when I build the solution, errors from database project are shown in the error list. – Sumit Apr 16 '11 at 08:14
  • @Sumit: Are you sure those are not errors from intellisense (do they show without a build?) To get rid of those close the file. – Richard Apr 16 '11 at 09:03
  • @Richard: I have created a new schema for my procs and using that schema while creating SP, the error is shown for this usages that "SP has unresolved reference object 'Schema name'" also I have used IF statement at the top of each SP, which checks if SP exists and then if it Exists then drops the SP and below is Create Statement for the SP. I am pretty sure these are not the errors that I should be concerned of, also I have closed all the SPs file, but still it shows in Error List, any idea what needs to be done ? – Sumit Apr 16 '11 at 09:16
  • This worked for me on VS2017 (I only turned off "Build" but left "Deploy" checked), and prevented problems with schema compare. – 8forty Aug 02 '18 at 22:07
3

My workaround (in VS2019) was:

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)

Activate SQLCMD Mode in menu SQL->Execution settings -> SQLCMD Mode

Hope this help.

dave
  • 2,291
  • 3
  • 19
  • 25
  • This is what fixed it for me in VS 2019 also; the file was already set to not build and the supression settings are for warnings, not errors, so SQL80001 couldn't be supressed, – Otis Apr 22 '20 at 16:31
  • Setting the SQLCMD mode fixed it for me. I had to click on the specific .sql file to get the SQL option to appear in the VS 2019 Menu. – Barry McDermid Apr 21 '21 at 13:14
2

Going back to the accepted answer for Warnings and Visual Studio 2019:

1) Right click on the database project and select properties Database solution

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

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.

1
  • Goto the project properties : Project -> Last menu
  • Navigate to SQLCLR Build tab in the project properties
  • Add SQL warnings in the Suppress Warnings Text box
  • Save the project file

Now you can build and see the warning are suppressed. (instructions as per vs2019)

Chenthil
  • 11
  • 2
0

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.

Sujeet
  • 51
  • 1
  • 5
-1
  1. 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.

  2. 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'

aWebdesigner09
  • 257
  • 2
  • 5
  • 17