I want to know if it is a correct thing to access SharePoint content database in code i.e (using custom SQL queries)? If not can anyone provide me with an explanation why shouldn't it be done?
- Directly querying or modifying the database can place extra load on a server, or can expose information to users in a way that violates security policies or personal information management policies.
- If server-side code must query data, then the process for acquiring that data should be through the built-in SharePoint object model, and not by using any type of query to the database.
- Client-side code that must modify or query data in SharePoint Products and Technologies can do this by using calls to the built-in SharePoint Web services that in turn call the object model.
- Direct modification of the SharePoint database or its data is not recommended because it puts the environment in an unsupported state.
- If a server component requires information from the database, it must get that data by using the appropriate items in the SharePoint object model, and not by trying to get the items from the data structures in the database through some query mechanism.
- Your custom queries might lead to incorrect data being retrieved.
- Direct SELECT statements against the database take shared read locks at the default transaction level so your custom queries might cause deadlocks and hence stability issues.
- Your queries are not guaranteed to work after applying any patches or service packs to SharePoint since Microsoft could change the database schema anytime.