I'm sorry if this has been asked, but I cannot find an answer. Can you query a SharePoint Document Library or site in a C# program using SQL?

If so, how do you set up the connection to SharePoint with C#?

3 Answers 3


In case you are planning to query a SharePoint database, please don't do that! It's not supported and wrong in many ways.

You should use SharePoint APIs to retrieve data you need. You can retrieve items from a SharePoint list via SPList object (not optimal for large list), or if you plan to query a list you should use CAML.

  • All the answers were helpful, but the links in your's really helped, thanks all.
    – sange
    Jan 6, 2011 at 13:21

You can use FullTextSQLQuery to issue SQL-like queries against the search index.

For simply returning a list of items, the standard is to use CAML queries, or LINQ to SharePoint is quickly becoming a popular method of doing this now.

Never attempt to directly query the underlying SQL content database, as this is not a supported practice.


Just to add my $2 on why you shouldn't connect directly to the SQL DB (and should use the SharePoint API as others have said), I blogged about this here: Supported Database Operations in SharePoint 2010.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.