Click here to Skip to main content
14,773,656 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a utility that reads the status of MicrosoftBizTalk Server resources .. specifically the ReceiveLocation component. My problem is that the program is submitting multiple entries of each item i.e each item in the data returned is being multiplied by 25 such that instead of persisting only 5 rows the data being persisted is 125. So for example instead of having just 1 row for my first row returned i have 25.

This is my program :

<pre> public List<BizTalk> GetBizTalkServicesStatistics()
        {

        
            List<BizTalk> model = new List<BizTalk>();

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

                ConnectionOptions options = new ConnectionOptions
                {

                    Username = "+username+",
                    Password = "+password+",
                    Authority = "+domain+"
                };

                
                var server = "+server+";
                // create the scope node so we can set the WMI root node correctly.
                ManagementScope Scope = new ManagementScope("\\\\" + server + "\\root\\MicrosoftBizTalkServer", options);
                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.

                    //if (args.Length == 0)
                    SelectQuery Query = new SelectQuery();               
                    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;

                    PropertyDataCollection envVarProperties = envVar.Properties;
                   
                    foreach (PropertyData envVarProperty in envVarProperties)
                    {
                        BizTalk bizTalk = new BizTalk();
                        bizTalk.Name = Convert.ToString(envVar["Name"]);
                        bizTalk.TransportType = Convert.ToString(envVar["AdapterName"]);
                        bizTalk.Uri = Convert.ToString(envVar["InboundTransportURL"]);
                        bizTalk.Status = Convert.ToString(envVar["Name"]);
                        bizTalk.ReceiveHandler = Convert.ToString(envVar["HostName"]);
                        bizTalk.ReceivePort = Convert.ToString(envVar["ReceivePortName"]);
                        bizTalk.RunDate = DateTime.Now;
                        bizTalk.ApplicationId = 24;
                        bizTalk.ServerId = 8;
                        bizTalk.InstanceName = "FBCZOP";                                          
                        model.Add(bizTalk);
                        
                    }
                }

                if (!ReceiveLocationFound)
                {
                    Console.WriteLine("No receive locations found matching the specified name.");
                }
            }

            catch (Exception excep)
            {
                ExceptionLogger.SendErrorToText(excep);
            }

            return model;
        }


Save Function
<pre> public void SaveStatistics(BizTalk entity)
        {
            List<BizTalk> ServerInfo = new List<BizTalk>();
            ServerInfo = GetBizTalkServicesStatistics();
            foreach (var di in ServerInfo)
            {
                entity.RunDate = di.RunDate;
                entity.Name = di.Name;
                entity.Status = di.Status;
                entity.Uri = di.Uri;
                entity.InstanceName = di.InstanceName;
                entity.ReceivePort = di.ReceivePort;
                entity.TransportType= di.TransportType;
                entity.RunDate = DateTime.Now;
                entity.ReceiveHandler = di.ReceiveHandler;                
                entity.ServerId = entity.ServerId;
                entity.ApplicationId = entity.ApplicationId;
                appEntities.BizTalk.Add(entity);
                appEntities.SaveChanges();
            }

        }


What am i missing?

What I have tried:

When i step through the code variable envVarProperties shows record count as 125 under envVarProperties << ResultsView :
https://drive.google.com/file/d/1Tdzu-6OIoyRNEpLgeqntX8lCnnqNBZAy/view?usp=sharing

whilst QueryCol variable shows count of 5 :
https://drive.google.com/file/d/1TdkPFD43awRBfQOceZ4luZlpNU7rLe03/view?usp=sharing
Posted
Updated 24-Jun-20 13:22pm

1 solution

Couldn't tell you what you're missing. There's nothing that stands out as wrong with the code you posted.

EF is writing 125 records because your code is giving it 125 objects to write.

You're going to have to step through the code, line-by-line, and watch what is happening on every variable.

We can't do that for you because we don't have your code (don't even think about trying to give it up to download!), your server setup, your data, ... nothing. This is going to be entirely on you.
   

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