DataSource cannot be found in SSRS
Hi everyone, I am programmatically trying to deploy report in SQL Server Reporting Services. I have created the Report Folder and Data Source Folder with the xxxx.rdl and XXX_DataSource respectively. But when trying to assign a DataSource to a report in Report Folder using following code: string dsname = aReport.DataSource.Split('/').Last(); rsc.CreateReport(aReport.Name, aReport.Folder, true, definition, null); DataSourceReference reference = new DataSourceReference reference.Reference = aReport.DataSource; DataSource[] dataSources = new DataSource[1]; DataSource ds = new DataSource();//creates new instance of DataSource ds.Item = (DataSourceDefinitionOrReference)reference; ds.Name = dsname; dataSources[0] = ds; //dataSources = rsc.GetItemDataSources("/" + aReport.DataSource); rsc.SetItemDataSources(@""+ aReport.Folder + "/" + aReport.Name, dataSources); it is generating an error saying: System.Web.Services.Protocols.SoapException: The data source 'XXX_DataSource' cannot be found. ---> Microsoft.ReportingServices.Diagnostics.Utilities.DataSourceNotFoundException: The data source 'XXX_DataSource' cannot be found. at Microsoft.ReportingServices.WebServer.ReportingService2005Impl.SetItemDataSources(String Item, DataSource[] DataSources) at Microsoft.ReportingServices.WebServer.ReportingService2005.SetItemDataSources(String Item, DataSource[] DataSources) Thanks in Advance! --Praveen
May 3rd, 2011 10:22am

Which class you uesd for aReport object ? SUHAS R. KUDEKAR http://suhaskudekar.blogspot.com/ Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful.
Free Windows Admin Tool Kit Click here and download it now
May 3rd, 2011 10:28am

Report Class I have used for aReport. The problem is rsc.SetItemDataSources(@""+ aReport.Folder + "/" + aReport.Name, dataSources); throwing exception System.Web.Services.Protocols.SoapException: The data source 'XXX_DataSource' cannot be found. ---> Microsoft.ReportingServices.Diagnostics.Utilities.DataSourceNotFoundException: The data source 'XXX_DataSource' cannot be found. at Microsoft.ReportingServices.WebServer.ReportingService2005Impl.SetItemDataSources(String Item, DataSource[] DataSources) at Microsoft.ReportingServices.WebServer.ReportingService2005.SetItemDataSources(String Item, DataSource[] DataSources)
May 4th, 2011 2:10am

Report Class I have used for aReport. The problem is rsc.SetItemDataSources(@""+ aReport.Folder + "/" + aReport.Name, dataSources); throwing exception System.Web.Services.Protocols.SoapException: The data source 'XXX_DataSource' cannot be found. ---> Microsoft.ReportingServices.Diagnostics.Utilities.DataSourceNotFoundException: The data source 'XXX_DataSource' cannot be found. at Microsoft.ReportingServices.WebServer.ReportingService2005Impl.SetItemDataSources(String Item, DataSource[] DataSources) at Microsoft.ReportingServices.WebServer.ReportingService2005.SetItemDataSources(String Item, DataSource[] DataSources)
Free Windows Admin Tool Kit Click here and download it now
May 4th, 2011 2:10am

Hi Praveen MB, SetItemDataSources basically replaces the existing data sources associated with the report with the new data sources reference or definition passed in. RS uses data source name to match the old datasources and the new data sources. If the name of a new data source cannot be found, a DataSourceNotFoundException will be thrown. I would suggest you check the data source name accordingly, and make sure they are exactly match to the defined data source in xxxx.rdl. Furthermore, if you can provide full code as well as the report definition code, I can help verify them on my server. Thanks, Eileen
May 8th, 2011 6:55am

Thanks for your immediate Reply Eileen. I am using CreateFolders() to create two folder: <Folders> <Folder> <Name>Reports_Folder</Name> <ParentFolder>/</ParentFolder> </Folder> <Folder> <Name>DataSource_Folder</Name> <ParentFolder>/</ParentFolder> </Folder> </Folders> And then CreateDataSources() to create Data source: <DataSource> <Name>Stride_DataSource</Name> <Folder>/DataSource_Folder</Folder> <Description>Stride Test Deploy</Description> <HideInListView>False</HideInListView> <Enabled>True</Enabled> <ConnectionString>Data Source=10.200.20.62;Initial Catalog=STRIDE6RQS</ConnectionString> <Extension>SQL</Extension> <CredentialRetrieval>Store</CredentialRetrieval> <WindowsCredentials>False</WindowsCredentials> <ImpersonateUser>True</ImpersonateUser> <ImpersonateUserSpecified>False</ImpersonateUserSpecified> <Prompt>null</Prompt> <UserName>sa</UserName> <Password>sa</Password> <EnabledSpecified>True</EnabledSpecified> </DataSource> private void CreateDataSources(string datasourceXMLFilePath) { ReportingService2005 reportingServicesClient = new ReportingService2005(); reportingServicesClient.Credentials = System.Net.CredentialCache.DefaultCredentials; DataSourceDefinition tempDataSource; XDocument xmlDoc = XDocument.Load(datasourceXMLFilePath); try { var result = from c in xmlDoc.Descendants("DataSource") select new { name = (string)c.Element("Name").Value, folder = (string)c.Element("Folder").Value, description = (string)c.Element("Description").Value, hideInListView = (string)c.Element("HideInListView").Value, enabled = (string)c.Element("Enabled").Value, connectionString = (string)c.Element("ConnectionString").Value, extension = (string)c.Element("Extension").Value, credentialRetrieval = (string)c.Element("CredentialRetrieval").Value, windowsCredentials = (string)c.Element("WindowsCredentials").Value, impersonateUser = (string)c.Element("ImpersonateUser").Value, impersonateUserSpecified = (string)c.Element("ImpersonateUserSpecified").Value, prompt = (string)c.Element("Prompt").Value, userName = (string)c.Element("UserName").Value, password = (string)c.Element("Password").Value, enabledSpecified = (string)c.Element("EnabledSpecified").Value }; foreach (var row in result) { CredentialRetrievalEnum credentialRetrieval; EnumConverter ec = new EnumConverter(typeof(CredentialRetrievalEnum)); credentialRetrieval = (CredentialRetrievalEnum)ec.ConvertFromString(row.credentialRetrieval); tempDataSource = new DataSourceDefinition(); tempDataSource.CredentialRetrieval = credentialRetrieval; tempDataSource.ConnectString = row.connectionString; tempDataSource.Enabled = bool.Parse(row.enabled); tempDataSource.EnabledSpecified = bool.Parse(row.enabledSpecified); tempDataSource.Extension = row.extension; tempDataSource.ImpersonateUserSpecified = bool.Parse(row.impersonateUserSpecified); tempDataSource.ImpersonateUser = bool.Parse(row.impersonateUser); tempDataSource.Prompt = row.prompt; tempDataSource.WindowsCredentials = bool.Parse(row.windowsCredentials); if (!String.IsNullOrEmpty(row.userName)) tempDataSource.UserName = row.userName; if (!String.IsNullOrEmpty(row.password)) tempDataSource.Password = row.password; try { reportingServicesClient.CreateDataSource(row.name,row.folder, true, tempDataSource, null); Logging.Log(string.Format("Data Source {0} has created successfully", row.name)); } catch (SoapException e) { Logging.Log(e.Detail.InnerXml.ToString()); } } } catch (Exception er) { Logging.Log(er.Message); } } And then CreateReports() to create Reports: private void CreateReports(Report[] reports) { ReportingService2005 rsc = new ReportingService2005(); rsc.Credentials = System.Net.CredentialCache.DefaultCredentials; foreach (Report aReport in reports) { Byte[] definition = null; Warning[] warnings = null; try { FileStream stream = File.OpenRead(aReport.Path); definition = new Byte[stream.Length]; stream.Read(definition, 0, (int)stream.Length); stream.Close(); } catch (IOException e) { Logging.Log(e.Message); } string dsname = aReport.DataSource.Split('/').Last(); rsc.CreateReport(aReport.Name, aReport.Folder, true, definition, null); DataSourceReference reference = new DataSourceReference(); reference.Reference = aReport.DataSource; DataSource[] dataSources = new DataSource[1];//creates an array of 1 of DataSource DataSource ds = new DataSource();//creates new instance of DataSource ds.Item = (DataSourceDefinitionOrReference)reference; ds.Name = dsname; dataSources[0] = ds; //dataSources = rsc.GetItemDataSources("/" + aReport.DataSource); rsc.SetItemDataSources(@""+ aReport.Folder + "/" + aReport.Name, dataSources); if (warnings != null) { foreach (Warning warning in warnings) { Logging.Log(string.Format("Report: {0} has warnings", warning.Message)); } } } Thanks in Advance, Praveen
Free Windows Admin Tool Kit Click here and download it now
May 9th, 2011 6:03am

Thanks for your immediate Reply Eileen. I am using CreateFolders() to create two folder: <Folders> <Folder> <Name>Reports_Folder</Name> <ParentFolder>/</ParentFolder> </Folder> <Folder> <Name>DataSource_Folder</Name> <ParentFolder>/</ParentFolder> </Folder> </Folders> And then CreateDataSources() to create Data source: <DataSource> <Name>Stride_DataSource</Name> <Folder>/DataSource_Folder</Folder> <Description>Stride Test Deploy</Description> <HideInListView>False</HideInListView> <Enabled>True</Enabled> <ConnectionString>Data Source=10.200.20.62;Initial Catalog=STRIDE6RQS</ConnectionString> <Extension>SQL</Extension> <CredentialRetrieval>Store</CredentialRetrieval> <WindowsCredentials>False</WindowsCredentials> <ImpersonateUser>True</ImpersonateUser> <ImpersonateUserSpecified>False</ImpersonateUserSpecified> <Prompt>null</Prompt> <UserName>sa</UserName> <Password>sa</Password> <EnabledSpecified>True</EnabledSpecified> </DataSource> private void CreateDataSources(string datasourceXMLFilePath) { ReportingService2005 reportingServicesClient = new ReportingService2005(); reportingServicesClient.Credentials = System.Net.CredentialCache.DefaultCredentials; DataSourceDefinition tempDataSource; XDocument xmlDoc = XDocument.Load(datasourceXMLFilePath); try { var result = from c in xmlDoc.Descendants("DataSource") select new { name = (string)c.Element("Name").Value, folder = (string)c.Element("Folder").Value, description = (string)c.Element("Description").Value, hideInListView = (string)c.Element("HideInListView").Value, enabled = (string)c.Element("Enabled").Value, connectionString = (string)c.Element("ConnectionString").Value, extension = (string)c.Element("Extension").Value, credentialRetrieval = (string)c.Element("CredentialRetrieval").Value, windowsCredentials = (string)c.Element("WindowsCredentials").Value, impersonateUser = (string)c.Element("ImpersonateUser").Value, impersonateUserSpecified = (string)c.Element("ImpersonateUserSpecified").Value, prompt = (string)c.Element("Prompt").Value, userName = (string)c.Element("UserName").Value, password = (string)c.Element("Password").Value, enabledSpecified = (string)c.Element("EnabledSpecified").Value }; foreach (var row in result) { CredentialRetrievalEnum credentialRetrieval; EnumConverter ec = new EnumConverter(typeof(CredentialRetrievalEnum)); credentialRetrieval = (CredentialRetrievalEnum)ec.ConvertFromString(row.credentialRetrieval); tempDataSource = new DataSourceDefinition(); tempDataSource.CredentialRetrieval = credentialRetrieval; tempDataSource.ConnectString = row.connectionString; tempDataSource.Enabled = bool.Parse(row.enabled); tempDataSource.EnabledSpecified = bool.Parse(row.enabledSpecified); tempDataSource.Extension = row.extension; tempDataSource.ImpersonateUserSpecified = bool.Parse(row.impersonateUserSpecified); tempDataSource.ImpersonateUser = bool.Parse(row.impersonateUser); tempDataSource.Prompt = row.prompt; tempDataSource.WindowsCredentials = bool.Parse(row.windowsCredentials); if (!String.IsNullOrEmpty(row.userName)) tempDataSource.UserName = row.userName; if (!String.IsNullOrEmpty(row.password)) tempDataSource.Password = row.password; try { reportingServicesClient.CreateDataSource(row.name,row.folder, true, tempDataSource, null); Logging.Log(string.Format("Data Source {0} has created successfully", row.name)); } catch (SoapException e) { Logging.Log(e.Detail.InnerXml.ToString()); } } } catch (Exception er) { Logging.Log(er.Message); } } And then CreateReports() to create Reports: private void CreateReports(Report[] reports) { ReportingService2005 rsc = new ReportingService2005(); rsc.Credentials = System.Net.CredentialCache.DefaultCredentials; foreach (Report aReport in reports) { Byte[] definition = null; Warning[] warnings = null; try { FileStream stream = File.OpenRead(aReport.Path); definition = new Byte[stream.Length]; stream.Read(definition, 0, (int)stream.Length); stream.Close(); } catch (IOException e) { Logging.Log(e.Message); } string dsname = aReport.DataSource.Split('/').Last(); rsc.CreateReport(aReport.Name, aReport.Folder, true, definition, null); DataSourceReference reference = new DataSourceReference(); reference.Reference = aReport.DataSource; DataSource[] dataSources = new DataSource[1];//creates an array of 1 of DataSource DataSource ds = new DataSource();//creates new instance of DataSource ds.Item = (DataSourceDefinitionOrReference)reference; ds.Name = dsname; dataSources[0] = ds; //dataSources = rsc.GetItemDataSources("/" + aReport.DataSource); rsc.SetItemDataSources(@""+ aReport.Folder + "/" + aReport.Name, dataSources); } Thanks in Advance, Praveen
May 9th, 2011 6:04am

Hi Praveen, Thanks for the prompt reply and updating with the codes. To my understanding, the DataSource XML structure is defined by yourself rather than the DataSource setting in the xxxx.RDL file, right? If that is the case, what I suggested in my previously reply was "check the data source name accordingly, and make sure they are exactly match to the defined data source in xxxx.rdl." What I mean is that, open the xxxx.rdl file in a notepad for example, and check the following XML code, <DataSources> <DataSource Name="DataSource1"> ... </DataSource> </DataSources> Make sure the DataSource Name is exactly matched to the name "Stride_DataSource", or you need to rename "Stride_DataSource" to the DataSource name used in xxxx.RDL. If you have any question, please feel free to ask. Thanks, Eileen.
Free Windows Admin Tool Kit Click here and download it now
May 9th, 2011 10:34am

Hi Eileen, Thanks again for your reply. Yes the problem was the Report which I was Uploading to the server was having different datasource and hence it is not getting the Datasource which I have defined in my Datasource xml file. Now it's working perfectly OK. Thanks for your Help.
May 9th, 2011 11:45am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics