Expand Minimize

Do not query SharePoint databases directly

It is not allowed to read or write directly to SharePoint databases. Use API, webservices etc. instead.

CheckId SPC030204
TypeName DoNotQuerySharePointDatabasesDirectly
Severity Error
Type Assembly

Remove the statement for reading from the SharePoint database (see Remarks for limitations of this rule).
Microsoft Statement regarding read operations of SharePoint database:
Reading from the SharePoint databases programmatically, or manually, can cause unexpected locking within Microsoft SQL Server which can adversely affect performance. Any read operations against the SharePoint databases that originate from queries, scripts, .dll files (and so on) that are not provided by the Microsoft SharePoint Development Team or by Microsoft SharePoint Support will be considered unsupported if they are identified as a barrier to the resolution of a Microsoft support engagement.
If unsupported read operations are identified as a barrier to the resolution of support engagement, the database will be considered to be in an unsupported state. To return the database to a supported state, all unsupported read activities must stop

The rule may lead to wrong results. The rule can only check the appeareance of SQLCommand, OdbcCommand or OleDbCommand which indicates database access. If one of these types is detected the rule can only check defined strings in the code for appearances of names of SharePoint database tables, views and stored procedures. But the rule is too important to not check for database access.

To suppress this violation in managed code add the following attribute to the method which contains the instruction (available since SPCAF version v5.2). Learn more about SuppressMessage here.

// Important: Ensure to have #define CODE_ANALYSIS at the beginning of your .cs file
[SuppressMessage("SPCAF.Rules.SupportabilityGroup", "SPC030204:DoNotQuerySharePointDatabasesDirectly", Justification = "Provide reason for suppression here")]
Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.