1

I am creating an application to upload SSRS .rdl files to our report server. This is using ReportingService2010()

The upload of the .RDL file works fine.

Next, the application should assign a specified datasource to the uploaded .RDL file, but this element is failing. My code is shown below:

DataSource[] dsarray = new DataSource[1];

string DSName = "MyDataSource";

DataSourceReference reference = new DataSourceReference();

DataSource ds = new DataSource();

dsarray[0] = new DataSource();

reference.Reference = "/" + DSName;

ds.Item = reference;
ds.Name = "/" + DSName;

dsarray[0] = ds;

rs.SetItemDataSources("/" + location + "/" + filename, dsarray);

I get the following error message:

The following error occured:

The data source '/MyDataSource' cannot be found. Microsoft.ReportingServices.Diagnostics.Utilities.DataSourceNotFoundException: The data source '/MyDataSource' cannot be found.

I'm pretty sure I'm very close, but I just can't get it working. I have tried many different solutions & looked online extensively (including stack overflow!), but I can't find examples relevant to my issue. Most discussions relate to ReportingServices2005.

I should mention my datasource resides in the root folder '/' as this is a development server.

I am relatively inexperienced with c# so perhaps I am missing something obvious. Any info/idea's would be very much appreciated, many thanks in advance.

Pedram
  • 6,256
  • 10
  • 65
  • 87
BSS_Tris
  • 21
  • 6
  • Check the permissions for the 'Data Source' and compare them to the permissions for the report. Do they match? – tgolisch Aug 03 '16 at 13:44
  • Unfortunately they do match. I'm pretty confident the issue is code based (although I could be wrong). Thank you for the suggestion. – BSS_Tris Sep 06 '16 at 15:28
  • This SO article has code very similar to yours, but yours is missing a few subtle details. http://stackoverflow.com/questions/16083951/ssrs-rdl-mapping-datasources-programmatically – tgolisch Sep 06 '16 at 15:50
  • Thanks for the suggestion. I have analysed the code, & made a few minor modifications but I still get the "DataSourceNotFoundException:" error message. I have looked in the "ReportServer$REPORTING" database & the datasource path & name I am specifying is definitely correct. So strange as I can deploy reports without issue. Restarting the reporting server did not help either. Am genuinely baffled! – BSS_Tris Sep 07 '16 at 12:15
  • If you open your .RDL file, using notepad, and look at the `` element, is the `Name` "MyDataSource" or "/MyDataSource", or something else? – tgolisch Sep 07 '16 at 14:15
  • The name is definately 'MyDataSource' (I have removed the '/' from my code as this was incorrect). What is interesting though, is the datasources appears to be stored inside the [ReportServer$REPORTING] database, rather than in the file folder structure. I am going to run a trace to see what happens when I manually attach a datasource to a report, perhaps this might give me some more clues. – BSS_Tris Sep 08 '16 at 14:53

1 Answers1

1

After a lot of research & failed attempts I finally stumbled across a solution.

The code below will assign a datasource selected from the drop down ddDataSourceSelect, to the your required SSRS .rdl file:

string DSName = ddDataSourceSelect.SelectedValue.ToString();

List<ReportService2010.ItemReference> itemRefs = new List<ReportService2010.ItemReference>();
ReportService2010.DataSource[] itemDataSources = rs.GetItemDataSources("/" + location + "/" + filename);

foreach (ReportService2010.DataSource itemDataSource in itemDataSources)
{
    ReportService2010.ItemReference itemRef = new ReportService2010.ItemReference();
    itemRef.Name = itemDataSource.Name;

    itemRef.Reference = "/" + DSName;

    itemRefs.Add(itemRef);
}

rs.SetItemReferences("/" + location + "/" + filename, itemRefs.ToArray());

Rather than simply embedding a datasource, this resets the datasource. I think the key change was using 'SetItemReferences()' rather than 'SetItemDataSources()'. I would not have guessed this.

Many thanks to the following post for their solution that allowed me to solve this issue:

Deploying SSRS RDL files from VB.Net - Issue with shared datasources

I hope this solution can help other coders :)

Community
  • 1
  • 1
BSS_Tris
  • 21
  • 6