Поделиться через


How to: Suppress Database Code Analysis Warnings

When you analyze the Transact-SQL code in your database project, you might find one or more warnings that you can safely ignore. To prevent those warnings from appearing every time that you build or analyze that code, you can suppress them for one or more files in your project.

If you want to suppress a warning for all files in your project, you can disable the rule. For more information, see How to: Enable and Disable Specific Rules for Static Analysis of Database Code. However, you should not suppress a warning or disable a rule unless you clearly understand all the contexts in which it might come up. For example, you might suppress a warning for a specific file if it contains a very small table that might be scanned. But you do not want to suppress the warning in other files or disable the rule if your project contains tables that are large enough to decrease performance if they were scanned.

Unlike managed code, you do not suppress a warning for Transact-SQL code by adding attributes to it. Instead, you automatically add an entry for each warning to a file that is named StaticCodeAnalysis.SuppressMessages.xml. This XML file is located in the same folder that contains the database project file (.dbproj). For each warning that you suppress, the XML file contains the path and name of the file for which you are suppressing the warning, the rule category, and that number of the rule.

To suppress one or more warnings

  1. If you have already opened your database project and analyzed the code, go to step 5.

  2. Open the solution that contains your database project.

  3. In Solution Explorer, click your database project.

  4. On the Data menu, point to Static Code Analysis, and click Run.

    Your Transact-SQL code is analyzed, and any errors and warnings appear in the Error List.

  5. In the Error List, right-click the warning that you want to suppress, and click Suppress Static Code Analysis Message(s).

    Note

    You can suppress multiple warnings at the same time by highlighting them, right-clicking any one of them, and clicking Suppress Static Code Analysis Message(s).

    An entry for each warning that you suppress is added to the suppression file.

See Also

Tasks

How to: Enable and Disable Specific Rules for Static Analysis of Database Code

How to: Analyze Transact-SQL Code to Find Defects

How to: Stop Suppressing Warnings for Database Code Analysis

How to: Suppress Warnings by Using the Menu Item

Concepts

Analyzing Database Code to Improve Code Quality