Click here to Skip to main content
15,867,834 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a program that will query for the state of BizTalk resources, specifically the ReceiveLocations component. When i run the sample program obtained from
C:\Program Files (x86)\Microsoft BizTalk Server 2013 R2\SDK\Samples\Admin\WMI\Enumerate Receive Locations
i get error Invalid Namespace on the line :

C#
ManagementObjectCollection QueryCol = Searcher.Get();


with stack trace :
C#
at System.Management.ThreadDispatch.Start()
  at System.Management.ManagementScope.Initialize()
  at System.Management.ManagementObjectSearcher.Initialize()
  at System.Management.ManagementObjectSearcher.Get()
  at Microsoft.Samples.BizTalk.WmiAdmin.EnumerateWMIClasses.Main(String[] args) in C:\Users\tshumae.FBC\Desktop\BIZTALK\CSharp\EnumRLs.cs:line 114


This is the full program :

C#
<pre>[STAThread]
		static void Main(string[] args)
		{
			// Display help information 
			if (args.Length > 0)
			{
					if (args[0] == "/?") 
					{
						....
						....
					}
			}

			try 
			{	
				//Create the WMI search object.
				ManagementObjectSearcher Searcher = new ManagementObjectSearcher();

				// create the scope node so we can set the WMI root node correctly.
				ManagementScope Scope = new ManagementScope("root\\"+server+"");
				Searcher.Scope = Scope;
			
				// Build a Query to enumerate the MSBTS_ReceiveLocation instances if an argument
				// is supplied use it to select only the matching RL.
				SelectQuery Query = new SelectQuery(); 
				if (args.Length == 0) 
					Query.QueryString="SELECT * FROM MSBTS_ReceiveLocation";
				else
					Query.QueryString="SELECT * FROM MSBTS_ReceiveLocation WHERE Name = '" + args[0] + "'";

				// Set the query for the searcher.
				Searcher.Query = Query;

				// Execute the query and determine if any results were obtained.
				ManagementObjectCollection QueryCol = Searcher.Get();

				// Use a bool to tell if we enter the for loop
				// below because Count property is not supported
				bool ReceiveLocationFound = false;

				// Enumerate all properties.
				foreach (ManagementBaseObject envVar in QueryCol)
				{
					// There is at least one Receive Location
					ReceiveLocationFound = true;

					Console.WriteLine("**************************************************");
					Console.WriteLine("Receive Location:  {0}", envVar["Name"]);
					Console.WriteLine("**************************************************");

					PropertyDataCollection envVarProperties = envVar.Properties;
					Console.WriteLine("Output in the form of: Property: {Value}");
				
					foreach (PropertyData envVarProperty in envVarProperties) 
					{					
						Console.WriteLine(envVarProperty.Name+ ":\t" + envVarProperty.Value);
					}
				}
					
				if (!ReceiveLocationFound) 
				{
					Console.WriteLine("No receive locations found matching the specified name.");
				} 
			}

			catch(Exception excep)
			{
				Console.WriteLine(excep.ToString());
			}
			
			Console.WriteLine("\r\n\r\nPress Enter to continue...");
			Console.Read();
		}


What am i missing? Is there anything specific i need to configure to query BizTalk resources beyond the System.Management namespace or its an issue with the sample code itself?

What I have tried:

I have tried using the code in a separate MVC application where WMI queries are working but i get the same error. The WMI queries in the MVC application are however for querying remote server disk statistics and not BizTalk Server services.
Posted
Updated 18-Jun-20 0:39am

1 solution

Start by using the debugger to find out what is in the Query and server variables. You don't show the definition of server and that could easily generate the problem.
THen check that Certificates are installed - if they aren't then MSBTS_ReceiveLocation[^] won't work.
 
Share this answer
 
Comments
Tshumore 18-Jun-20 7:04am    
server is getting the BizTalkserver record from a database table. I have stepped through the value is correct :
root\\FBXDCZIMFTS01
I have even tried to use server name with fully qualified name that specifies the BizTalk database but get same exception :
root\\FBXDCZIMFTS01:BizTalkMgmtDb

When i inspect query this is what i get : https://drive.google.com/file/d/1natMNMkHP2KVUzt60sZSRjU3ecthSPox/view?usp=sharing

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900