Click here to Skip to main content
15,887,676 members
Home / Discussions / C#
   

C#

 
Questionobject reference not set to an instance of an object. Pin
abdo.kouta22-May-15 3:31
abdo.kouta22-May-15 3:31 
GeneralRe: object reference not set to an instance of an object. Pin
Sascha Lefèvre22-May-15 3:55
professionalSascha Lefèvre22-May-15 3:55 
GeneralRe: object reference not set to an instance of an object. Pin
abdo.kouta22-May-15 4:13
abdo.kouta22-May-15 4:13 
AnswerRe: object reference not set to an instance of an object. Pin
OriginalGriff22-May-15 4:26
mveOriginalGriff22-May-15 4:26 
GeneralRe: object reference not set to an instance of an object. Pin
Eddy Vluggen22-May-15 4:36
professionalEddy Vluggen22-May-15 4:36 
SuggestionRe: object reference not set to an instance of an object. Pin
Richard Deeming22-May-15 5:08
mveRichard Deeming22-May-15 5:08 
GeneralRe: object reference not set to an instance of an object. Pin
Eddy Vluggen22-May-15 6:37
professionalEddy Vluggen22-May-15 6:37 
QuestionC# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 2:28
Member 1171127722-May-15 2:28 
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.

I've also changed VisualStudio to break when an exception is thrown, and it doesn't

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

**Windows Forms Code**

C#
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.

modified 22-May-15 9:17am.

AnswerRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 2:42
professionalSascha Lefèvre22-May-15 2:42 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 2:51
Member 1171127722-May-15 2:51 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 3:17
professionalSascha Lefèvre22-May-15 3:17 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 3:22
Member 1171127722-May-15 3:22 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 3:29
professionalSascha Lefèvre22-May-15 3:29 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 3:47
Member 1171127722-May-15 3:47 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 3:57
professionalSascha Lefèvre22-May-15 3:57 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 3:59
Member 1171127722-May-15 3:59 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 4:12
professionalSascha Lefèvre22-May-15 4:12 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 4:15
Member 1171127722-May-15 4:15 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Member 1171127722-May-15 4:17
Member 1171127722-May-15 4:17 
GeneralRe: C# Stops Executing When Opening A Connection To MySql Pin
Sascha Lefèvre22-May-15 4:35
professionalSascha Lefèvre22-May-15 4:35 
Questionhow to keep datagridview in editmode on pressing of arrow keys Pin
Muhammad Waqas Aziz22-May-15 0:32
Muhammad Waqas Aziz22-May-15 0:32 
AnswerRe: how to keep datagridview in editmode on pressing of arrow keys Pin
Sascha Lefèvre22-May-15 1:00
professionalSascha Lefèvre22-May-15 1:00 
GeneralRe: how to keep datagridview in editmode on pressing of arrow keys Pin
Muhammad Waqas Aziz26-May-15 23:31
Muhammad Waqas Aziz26-May-15 23:31 
AnswerRe: how to keep datagridview in editmode on pressing of arrow keys Pin
Simon_Whale22-May-15 1:23
Simon_Whale22-May-15 1:23 
Questionhelp in datagride view CellLeave Pin
aahamdan21-May-15 21:00
aahamdan21-May-15 21:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.