5
votes

I want to retrieve some data. How can I make a query on a Sharepoint database?

3
Do you know you can also accept answers?Janis Veinbergs
Remote Desktop into the machine that hosts your sql database and run a TSql query through Microsoft Sql Server Management Studio. As mentioned below, you really shouldn't do anything but a SELECT statement, and even then there can be deadlock issues.Kellen Stuart

3 Answers

11
votes

You shouldn't because of these reasons:

  1. This is completely unsupported by the EULA you agreed to when you installed SharePoint. (I have to add a note that changing or calling triggers (except some) directly is unsupported, but not selecting)
  2. Your queries are not guaranteed to work after applying any patches or service packs to SharePoint since Microsoft could change the database schema anytime.
  3. Directly querying the database can place extra load on a server and hence performance issues.
  4. 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.
  5. Your custom queries might lead to incorrect data being retrieved.

Let me clarify, that #1 DOES NOT ALLOW you to modify sharepoint database in any way. SELECT`ing is permitted, however, as mentioned, that may lead to other problems.

However, if you are not interested in these points, then just use Visual Studio to connect to existing database, just do the regular procedure on how you connect to any other database.

But you can make your own database and store some additional information there.

Access SharePoint data the right way

  1. Use SharePoint Object Model (Code can only be run on SharePoint server)
  2. Use SharePoint WebServices (Run code from anywhere, from any application)
  3. SharePoint 2013 now features REST API.
7
votes

I have one thing to add. If you do decide to query sharepoint content databases directy, use the NOLOCK hint to prevent shared lock being taken out and potentially creating dead locks in the application.

0
votes

If you don't mind using other proprietary Microsoft programs, Access/Excel/PowerBI all offer native connectivity to data stored in sharepoint lists/document libraries/meta data.