Accessing SharePoint List Items with SQL Server 2005 Reporting Services

Recently I had to connect to a SharePoint List to access some data.  While there is a data extension available from Enesys (including a free Community edition) to do this I though I would first make an attempt using the out-of-the-box options.

The first step was getting connected to any of the list services.  I chose to start with GetListCollection because it required no parameters (aka it was simple to use).  Here is what I did to get connected:

  1. Right click the Shared Data Sources folder in your report project and select Add New Data Source.
  2. In the Shared Data Source dialog give your data source a name and from the Type drop down list select XML.
  3. In the Connection string text field put the URL to the Lists service (e.g. http://<sharepointserver>/<subarea_optional>/_vti_bin/lists.asmx)
  4. On the Credentials tab select Use Windows Authentication (Integrated Security) and click OK.
  5. Create a new or open an existing report definition and select the Data tab.
  6. From the Dataset drop down list select New Dataset.
  7. Provide a Name for your data set and select the Data source from the drop down list that you created earlier.
  8. In the Query text field put in the following query (note that there is no trailing slash on the Namespace attribute -- this is important!):
<Query>
    <Method Namespace="http://schemas.microsoft.com/sharepoint/soap" Name="GetListCollection" />
</Query>
  1. Click OK and then click the Run in the Data tab.

You should see in the preview window at this point a dataset result from the GetListCollection call.  In addition the Datasets tool window will show all the fields returned in the dataset for you to leverage in your report.

Now the GetListCollection is useful, but it's not the method call that we all really want - GetListItems.  To do this we'll leverage the same shared data source:

  1. Create a new or open an existing report definition and select the Data tab.
  2. From the Dataset drop down list select New Dataset.
  3. Provide a Name for your data set and select the Data source from the drop down list that you created earlier.
  4. In the Query text field put in the following query (note that there is no trailing slash on the Namespace attribute -- this is important!):
<Query>
    <Method Namespace="http://schemas.microsoft.com/sharepoint/soap/" Name="GetListItems"/>
    <SoapAction>http://schemas.microsoft.com/sharepoint/soap/GetListItems</SoapAction>
</Query>
  1. In the Parameters tabs add the following entries while leaving the Value blank:
    1. listName
    2. viewName
    3. query
    4. viewFields
    5. rowLimit
    6. queryOptions
  2. Click OK and then click the Run in the Data tab.
  3. In the Define Query Parameters dialog enter the name of your list in listName and click OK.

I have found various oddities while working with the XML data source like random failures for no apparent reason.  I'm still playing with it but I thought I would share my learnings for others.  You can, of course, refine your request with the various parameters outlined in the SDK.

As you work with Web Services and Reporting Services I highly recommend Fiddler as a troubleshooting tool.  The trailing slash note above was discovered because I could see what was going on at the HTTP layer (the SoapAction header had "...soap//GetListCollection").

Comments Subscribe to Post Comments Feed

Data Cogs Information Technology said:
Data Cogs Information Technology said:
Moojjoo said:

TITLE: Microsoft Report Designer

------------------------------

An error occurred while executing the query.

Failed to execute web request for the specified URL.

------------------------------

ADDITIONAL INFORMATION:

Failed to execute web request for the specified URL. (Microsoft.ReportingServices.DataExtensions)

------------------------------

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="schemas.xmlsoap.org/.../" xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema">

 <soap:Body>

   <soap:Fault>

     <faultcode>soap:Server</faultcode>

     <faultstring>Exception of type Microsoft.SharePoint.SoapServer.SoapServerException was thrown.</faultstring>

     <detail>

       <errorstring xmlns="schemas.microsoft.com/.../">Value does not fall within the expected range.</errorstring>

     </detail>

   </soap:Fault>

 </soap:Body>

</soap:Envelope>

------------------------------

BUTTONS:

OK

------------------------------

Kiran said:

Hi

When I tried the following code for getting Listitems I am getting

"There is an error in the query. Failed to execute web request for the specified URL."

Error.

Please suggest....

---------------------------

<Query>  

   <Method Namespace="schemas.microsoft.com/.../soap" Name="GetListItems"/>  

   <SoapAction>schemas.microsoft.com/.../SoapAction>  

    <Parameters>

      <Parameter Name="listName ">

          <DefaultValue>/</DefaultValue>

      </Parameter>

 <Parameter Name="viewName  ">

          <DefaultValue>/</DefaultValue>

      </Parameter>

 <Parameter Name="query ">

          <DefaultValue>/</DefaultValue>

      </Parameter>

 <Parameter Name="viewFields  ">

          <DefaultValue>/</DefaultValue>

      </Parameter>

 <Parameter Name="rowLimit  ">

          <DefaultValue>/</DefaultValue>

      </Parameter>

 <Parameter Name="queryOptions ">

          <DefaultValue>/</DefaultValue>

      </Parameter>

  </Parameters>

</Query>

Colin said:

Moojjoo - There is something about your query it doesn't like.  It's hard to tell without more information.  I would recommend using Fiddler (www.fiddlertool.com) as a proxy to see what the conversation looks like.  If you can provide more information on the query I might be able to help further.

Kiran - You need to provide the parameters in the parameter tab per my post.

Nathan said:

You have spaces after the end of the parameter names.  Remove those and it should work

Kiran said:

Thanks for that Colin,

Now I am getting results from SharepointLists. It shows in data tab but when I hit preview I am getting an error which says "Root element is missing"

I have added those 6 parameters as report parameters and assigning them to dataset.

I have also added <?xml version="1.0" encoding="utf-8" ?> tag to query

like <?xml version="1.0" encoding="utf-8" ?>

<Query>  

<Method Namespace="schemas.microsoft.com/.../" Name="GetListItems"/>

<SoapAction>schemas.microsoft.com/.../SoapAction>  

</Query>

But I am still getting that error...

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:soap="schemas.xmlsoap.org/.../" xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema">

<soap:Body>

  <soap:Fault>

    <faultcode>soap:Server</faultcode>

    <faultstring>Exception of type Microsoft.SharePoint.SoapServer.SoapServerException was thrown.</faultstring>

    <detail>

      <errorstring xmlns="schemas.microsoft.com/.../">The root element is missing</errorstring>

    </detail>

  </soap:Fault>

</soap:Body>

</soap:Envelope>

Thanks

Shai Das said:

Thanks for publishing this article. Saved me quite a bit of time. Kiran , what you need to do is add another parameter called webID to the list . This is not documented in the MOSS SDK.Before going further I would like to mention that you can parse lists as well as document libraries in MOSS using the lists webservice. This is not documented and I had heaps of trouble figuring it out , quite silly considering that there is a picture library web service but not one for document library. Anyways I'll stop winging and share my learnings .

As a general approach to creating SSRS 2005 reports based on MOSS webservices( I write this after spending the whole of today doing this and this approach works for me ). I assume basic familiarity with SSRS , webservices and MOSS

1. Download fiddler from the link provided by the author of this article and install it

2. Create your datasource by pointing to the target webservice path which will be sharepointsite/.../webservicename.asmx. Use integrated authentication

3. Browse to the asmx file in your browser and click on the required method. Look at the soap 1.1 request definition . This willl give you the required parameters as well as the schema. Create your query in the following format

<Query>  

   <Method Namespace="schemas.microsoft.com/.../" Name="Method name"/>  

   <SoapAction>schemas.microsoft.com/.../SoapAction>  

</Query>

Both the namespace as well as the soapaction can be seen from the asmx method definiton ( point 3 above)

4. Define the parameters in the same case as defined in the asmx method definition , making sure there are NO BLANK SPACES after or before the parameter names.

Some of these parameters are optional and hence do not need a value, I have been using SOAP UI ( a free tool ,google it ) for finding the optional parameters

5. Run your report and give values for the list name and other non optional parameters .

6. With every report request open fiddler , locate the request and double click on it to see the soap request being sent . Match this request to the method definition from step 3 above . If there are ANY differences , a space, a comma, a difference in case... youll get an error. Another strange thing is that in VS 2005, the parameters seem to keep disappearing so check that periodically .

Best of luck.

Allen Zhang said:

SQLServer2005ReportingServices与MOSS2007集成,使用SSRS制作报表,在MOSS中显示。

AccessingSharePointListIt...

MKeeper said:

I am passing in the following query for the GetListItems (I've already checked and my DataSource works fine with other parameters).

<Query>  

 <Method Namespace="schemas.microsoft.com/.../soap"">schemas.microsoft.com/.../" Name="GetListItems"/>  

<SoapAction>schemas.microsoft.com/.../soapGetListItems</SoapAction>">schemas.microsoft.com/.../SoapAction>  

<Parameters>

 <Parameter Name="listName"><DefaultValue></DefaultValue></Parameter>

 <Parameter Name="viewName"><DefaultValue></DefaultValue></Parameter>

 <Parameter Name="query"><DefaultValue></DefaultValue></Parameter>

 <Parameter Name="viewFields"><DefaultValue></DefaultValue></Parameter>

 <Parameter Name="rowLimit"><DefaultValue></DefaultValue></Parameter>

 <Parameter Name="queryOptions"><DefaultValue></DefaultValue></Parameter>

 <Parameter Name="webID"><DefaultValue></DefaultValue></Parameter>

</Parameters>

</Query>

I am getting the following error message back (through fiddler):

errorstring [ xmlns=schemas.microsoft.com/.../soap ]

Value does not fall within the expected range.

Any ideas ?

Shai said:

MKeeper

I am not sure how you are setting the listname parameter in your query . I am guessing that the list name is going in as null which is the default value. If you are using the report designer in VS then I would suggest you remove the param definition from your query and place it in the parameter tab for the dataset. Set it up with your list name as the default hardcoded value. Or try by changing your

<Parameter Name="listName"><DefaultValue></DefaultValue></Parameter>

to

<Parameter Name="listName"><Your list name></Parameter>

Cheers

Shai

David Wise's Sharepoint blog said:

There is a multitude of blogs that discuss how to access SharePoint data from SQL Reporting Services

David Wise's Sharepoint blog said:

There is a multitude of blogs that discuss how to access SharePoint data from SQL Reporting Services

Guy said:

Hi

After creating the XML datasource and dataset i simply cannot get the

query to run for even the most basic request.  Using Fiddler as suggested,

the error given is

“You do not have permission to view this directory or page using the

credentials that you supplied because your Web browser is sending a

WWW-Authenticate header field that the Web server is not configured to

accept.”

The datasource is configured for integrated security and i can paste in the

http address of the webservice and view it directly thru a browser.

Any idea what i can do to get this working?

Guy

Eduardo said:

Is there a way to read sharepoint list items directly from SQL Server? Maybe OPENDATASOURCE or something like it, using a similar approach as explained here?

Chance1234 said:

I was having a nightmare getting this to work , I kept getting

"There is an error in the query. Failed to execute web request for the specified URL."

after much back and fourth, i cut and pasted

schemas.microsoft.com/.../GetListItems

in the query window out to notepad and back in and hey presto it works.

Alex said:

GREAT Post!

I was able to get my query to work where it returns my fields in my list however, under the Report datasets, when I click on the plus symbol to expand my field list to use on my reports - mine is blank? It seems as if there are no fields returned for my query.

Any thoughts?

Alex said:

Nevermind....I figured it out!  newbie mistakes.

Thanks again - Great Post.

Dave said:

Here is a link to another option for connecting to Sharepoint List data from Reporting Services- www.teuntostring.net/.../finally-fixed-problem-w-reporting-over.html

Link to the orginal article explaining the code- www.teuntostring.net/.../reporting-over-sharepoint-lists-with.html

The 'Enesys RS Extension' product is based on the code in this blog article.

It helps to read the comments for trouble shooting and installation.

I was able to set this up on a vhd and filter sharepoint list data in the filter tab.

Only supports reporting on one list.

Have Your Say