1 Replies - 250 Views - Last Post: 22 May 2015 - 05:44 AM Rate Topic: -----

#1 dan789   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 22-May 15

C# Stops Executing When Opening A Connection To MySql

Posted 22 May 2015 - 05:24 AM

I am writing an application to transfer data from a simulated OPC server to a MySql Database. I am using some of the libraries from OPC Foundation - OPCNETAPI.DLL, OPCNETAPI.COM.DLL.

I have the program reading from the server happily, but it seems as soon as I open a connection inside the loop of reading data, it loops about 5 times and then stops executing.. There are no exceptions thrown and I have tried for hours to work it out and miserably failed.

Hopefully some one may know whats going on, but there is nothing obvious, hopefully the following code will spark ideas!

**Windows Forms Code**

 public void readplc()
            {
                Opc.URL url = new Opc.URL("opcda://localhost/Matrikon.OPC.Simulation.1");
                Opc.Da.Server server = null;
                OpcCom.Factory fact = new OpcCom.Factory();
                server = new Opc.Da.Server(fact, null);
                try
                {
    
                    server.Connect(url, new Opc.ConnectData(new System.Net.NetworkCredential()));
                }
                catch (Exception ecy)
                {
    
                }
                // Create a group
                Opc.Da.Subscription group;
                Opc.Da.SubscriptionState groupState = new Opc.Da.SubscriptionState();
                groupState.Name = "Group";
                groupState.Active = true;
                group = (Opc.Da.Subscription)server.CreateSubscription(groupState);
                // add items to the group.
                Opc.Da.Item[] items = new Opc.Da.Item[2];
                items[0] = new Opc.Da.Item();
                items[0].ItemName = "Random.Int1";
                items[1] = new Opc.Da.Item();
                items[1].ItemName = "Random.Time";
                items = group.AddItems(items);

                    group.DataChanged += new Opc.Da.DataChangedEventHandler(OnTransactionCompleted);

            }
    
            public void OnTransactionCompleted(object group, object hReq, Opc.Da.ItemValueResult[] items)
            {

                for (int i = 0; i < items.GetLength(0); i++)
                {
                 
                    try
                    {
    
                        string a = items[i].Value.ToString();
                        string b = items[i].ItemName;
                        string c = items[i].Key;

                        MySqlConnection conn = new MySqlConnection("server=localhost;user id=localhost;password=localhost;database=localhost;pooling=false"); 
                        conn.Open();
                        conn.Close();
                    }
                    catch (Exception ec)
                    {
                    }
                    
                }
    
            }



I have set break points throughout the code, stepped through everything possible and still nothing obvious that's causing the issue.

Is This A Good Question/Topic? 0
  • +

Replies To: C# Stops Executing When Opening A Connection To MySql

#2 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6292
  • View blog
  • Posts: 21,623
  • Joined: 05-May 12

Re: C# Stops Executing When Opening A Connection To MySql

Posted 22 May 2015 - 05:44 AM

Closing this since you've already got a duplicate post.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1