Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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#?

share|improve this question
add comment

3 Answers 3

up vote 8 down vote accepted

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.

share|improve this answer
    
All the answers were helpful, but the links in your's really helped, thanks all. –  sange Jan 6 '11 at 13:21
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
much more deserved +1 –  Falak Mahmood Jan 5 '11 at 23:34
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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