How to enumerate existing Reporting Service URL(s) from a given computer name
Hi All, I want to enumerate all existing Reporting Service Url(s) from a given computer name. So what should I do. Btw, I found an example from MSDN but I have been unable to get it work on my computer. It always throw an exception which is: "Invalid namespace". All prerequisite assumptions such as: Configuration files, ... etc are in the right folders. const string WmiNamespace = @"\\MY_COMPUTER_NAME\root\Microsoft\SqlServer\ReportServer\MSSQLSERVER\v10\Admin"; const string WmiRSClass = @"\\MY_COMPUTER_NAME\root\Microsoft\SqlServer\ReportServer\MSSQLSERVER\v10\admin:MSReportServer_ConfigurationSetting"; ManagementClass serverClass; ManagementScope scope; scope = new ManagementScope(WmiNamespace); // Connect to the Reporting Services namespace. scope.Connect(); // Create the server class. serverClass = new ManagementClass(WmiRSClass); // Connect to the management object. serverClass.Get(); if (serverClass == null) throw new Exception("No class found"); // Loop through the instances of the server class. ManagementObjectCollection instances = serverClass.GetInstances(); foreach (ManagementObject instance in instances) { Console.Out.WriteLine("Instance Detected"); PropertyDataCollection instProps = instance.Properties; foreach (PropertyData prop in instProps) { string name = prop.Name; object val = prop.Value; Console.Out.Write("Property Name: " + name); if (val != null) Console.Out.WriteLine(" Value: " + val.ToString()); else Console.Out.WriteLine(" Value: <null>"); } } Console.WriteLine("\n--- Press any key ---"); Console.ReadKey(); }
March 28th, 2011 4:06am

If I tweak the wmiNamespace to @"\\MACHINE_NAME\root\Microsoft\SqlServer\ReportServer" and then pass "MSReportServer_Instance" string value as a description to create an instance of ReportServer instance I get another error message which is "{Not found}". Does it mean the given namespace which is wmiNamespace is not correct ??? Kindly see the source code below for more details. public static IList<string> GetExistingReportingUrls() { var networkComputers = GetNetworkComputers(Win32.SV_101_TYPES.SV_TYPE_NT); var wmiNamespace = @"\\{0}\root\Microsoft\SqlServer\ReportServer"; foreach (var computer in networkComputers) { // Connect to the Reporting Services namespace. var scope = new ManagementScope(string.Format(wmiNamespace, computer.sv101_name)); scope.Connect(); var path = new ManagementPath("MSReportServer_Instance"); //MSReportServer_ConfigurationSetting // Create the server class. var serverClass = new ManagementClass(scope, path, new ObjectGetOptions()); // Connect to the management object. serverClass.Get(); if (serverClass == null) throw new Exception("No class found"); // Loop through the instances of the server class. ManagementObjectCollection instances = serverClass.GetInstances(); foreach (ManagementObject instance in instances) { Console.Out.WriteLine("Instance Detected"); PropertyDataCollection instProps = instance.Properties; foreach (PropertyData prop in instProps) { string name = prop.Name; object val = prop.Value; Console.Out.Write("Property Name: " + name); if (val != null) Console.Out.WriteLine(" Value: " + val.ToString()); else Console.Out.WriteLine(" Value: <null>"); } } Console.WriteLine("\n--- Press any key ---"); Console.ReadKey(); } return null; }
Free Windows Admin Tool Kit Click here and download it now
March 28th, 2011 8:01am

Hi, Please check if the information in the below link helps. It appears that some namespace have been moved. http://connect.microsoft.com/SQLServer/feedback/details/126560/reporting-services-wmi-provider-code-error Please click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH
March 28th, 2011 8:14am

Thank you Bilal Hani. I have been able to connect to run the below lines of code so I think the given namespace should be correct var wmiNamespace = @"\\{0}\root\Microsoft\SqlServer\ReportServer"; //{0} is localhost var scope = new ManagementScope(string.Format(wmiNamespace, computer.sv101_name)); scope.Connect(); var path = new ManagementPath("MSReportServer_Instance"); //MSReportServer_ConfigurationSetting // Create the server class. var serverClass = new ManagementClass(scope, path, new ObjectGetOptions()); // Connect to the management object. serverClass.Get(); => here is where I got an exception which is "{Not found}" Have you got any idea about that
Free Windows Admin Tool Kit Click here and download it now
March 28th, 2011 10:10am

Please try changing the first line of the code to var wmiNamespace = @"\\{0}\root\Microsoft\SqlServer\ReportServer\RS_MSSQLSERVER\v10"; I got the same error and above change resolved it. Depending on the version of SSRS it may be v9 perhaps in place of v10. Hope this helpsPlease click "Mark as Answer" if this resolves your problem or "Vote as Helpful" if you find it helpful. BH
March 29th, 2011 7:22am

That's it!!! Thank you very much
Free Windows Admin Tool Kit Click here and download it now
March 30th, 2011 5:12am

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

Other recent topics Other recent topics