Question

I've got a bunch of reports deployed as RDL's to a SSRS. Because of high security requirements, the db passwords change very frequently. It's become a huge task to keep up with the changes and having to modify dozens upon dozens of reports. This leads to my question...

Is it possible to programmatically set a data source or a connection string for a deployed report?

  • Could this be done using an app that modifies something in the report itself as it sits on the server?

  • Could this be done by modifying a shared data source from an app as the DS sits on the server?

  • Could it be done by embedding a script inside the report itself which retrieves the connection from say a web service?

Thanks

Was it helpful?

Solution

This can be done in multiple ways, I think one of the simplest is using the API of SSRS web service. The web service lets you manipulate all the reporting entities including the Data Sources.

As a solution to this issue it's possible to update the data sources credentials using calls to the web service every time the DB password changes (even automate it using some sort of trigger?).

I did something similar in a project where RDLs and data sources had to be generated, deployed and manipulated in runtime and it worked fine so updating data source must be feasible.

OTHER TIPS

Add a Service Reference to your project for your Reporting Service endpoint(http://ReportServerHost.mydomain.tld/ReportServer/ReportService2005.asmx). Use the following code to modify the Data Source password:

    public static void ChangeDataSourcePassword(string dataSourcePath, string password)
    {
        using (ReportingService2005SoapClient reportingService = new ReportingService2005SoapClient())
        {
            reportingService.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;

            try
            {  
                ServerInfoHeader serverInfo = null;
                DataSourceDefinition dataSourceDefinition = null;

                serverInfo = reportingService.GetDataSourceContents(dataSourcePath, out dataSourceDefinition);
                dataSourceDefinition.Password = password;
                serverInfo = reportingService.SetDataSourceContents(null, dataSourcePath, dataSourceDefinition);
            }
            catch (FaultException ex)
            {
                // Do something with the exception. Rethrow it and/or show it to the user.
                Console.WriteLine(string.Format("Failed to change the password on {0}: {1}", dataSourcePath, ex.Message));
                throw new ApplicationException("Failed to change the password on the Data Source.", ex);
            }
        }
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top