C# and mySQL Connection
I have been working on a financial analysis program for some time now, and have run into some what of a snag. Before I delve into the details, I just want to state that I am fairly new at C# so please pardon any noob statements.
The program takes data from a given financial market, processes it (very small pieces of data.. a number such as 1192.75 would be the longest double to come in), then saves the output from the processing to a mySQL database. It does this very rapidly many times a second (usually around 5 to 10 times per second, although sometimes more).
Now here comes the problem. The output which the program saves in the database is something I need to be able to access in real-time. However, the program has about a 1 to 2 minute lag in saving the output to the database. I have identified the part of the program most likely creating the lag and am having difficulty fixing it.
The main class has two parts to it: One method loads when the program first initializes, and the next method runs whenever a new piece of data comes in (usually around 5-10 times per second). The problem is that in the second method, I have to reestablish a connection to the mySQL database every single time, then input the data. Is there anyway that I could establish a connection to the mySQL database in the first method and use that connection in the second method, instead of having to constantly reestablish a connection to the database several times per second? I think that being able to do so would significantly improve the performance of the program, and may help to eliminate the lag.