Wednesday, November 05, 2008

How to get the URL to the reportserver programmatically

I was searching the net the other day to try to find a way to programmatically get the reporting server url from CRM. I thought that there must be some way to find it using the standard CRM webservice and I really looked throught the SDK and all the blogs I could find to see if anyone knew.

Finally I gave up and tried to find some other way to get it and I remembered that it is set in the registry so I wrote some code to get it from there and here it is in all it's simple glory:

RegistryKey regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\MSCRM");
string reportserver = regkey.GetValue("SQLRSServerURL").ToString();

And it worked but only just since it uses the server name and my VPN connection to the customers environment didn't bother with sending it to me why I have to manually add it to the hosts file.

The host file can be found at the path: C:\WINDOWS\system32\drivers\etc\hosts

and I added the row: CRMTESTSRV

Now my button which point to my aspx that redirects to a the report in pdf-format works just fine and is independant of the CRM server it is installed on.

The solution isn't supported as far as I know since you never know if they might change the registry value in the future (not very likely in an update but might happen in an upgrade). If anyone has any supported way of getting this URL, please comment this post.

This could also be done using javascripts but I find it easier to manage server side code and it doesn't add that much overhead considering the report has to be generated independantly of if I use aspx or javascript to open the report.

Gustaf Westerlund
Microsoft Dynamics CRM Architect



  1. Your solution will not work in multi tenet environment.
    You need to read from MSCRM_CONFIG , from the organization table the organization record and get the info from SRSURL column.

  2. Hi,
    Right you are. Thanks for the input.

    However, I'd like to avoid the management of connection strings to databases (since that will complicate deployment) which of course is possible by reading the value:
    "configdb" from the MSCRM key in the registry aswell.

    If you can decide on a strict setup of one multitenant CRM server and only one SSRS then you could probably manage generating the path using the org-name from the discovery service and the value "SQLRSServerURL" in the registry.

    I think consideration also has to be made if the solution is to be offline available. Any inputs on that topic Shai?

  3. Neither of these solutions are supported and it would be very nice if there was a supported way of getting the reporting services url.

    According to a colleague of mine who works with installations and configurations it is not supported (yet anyway) to have one CRM installation with multiple SSRS servers where the different tenants use different servers. That doesn't mean that it cannot be done, just that it isn't supported at the moment. He believes that it might be supported in future servicepacks of SQL-Server or Dyn CRM.

    Any more input on the subject is greatly appreciated.