dynamicweb09
asked on
how to use multiple instance of a db connection with multiple thread in C#.Net
I have a console application(C#). I want to use more than one instance of mysqlconnection.
I have a master table with 50000 rows. I want to split the data in 10 set and want to run some procedures parallel with the data. please help me.
I have a master table with 50000 rows. I want to split the data in 10 set and want to run some procedures parallel with the data. please help me.
ASKER
Thanks Igor for your reply.
Actually I want to run same procedure with different parameter parallel y. please help me
Actually I want to run same procedure with different parameter parallel y. please help me
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can I call Asynchronously? if yes then how?
Once again, I speak of my experience with SQL Server, so I am not sure that MySql has those, but the Command object has a series of BeginExecute methods that runs asynchronously. Since all the ADO.NET libraries follow the same model, you might have those on your side.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@kaufmed
As stated in your reference, MARS works through "Interleaved execution". It is my understanding and my experience that from the application point of view, you feel that the result is the same as if the stuff was working in real parallel execution. If you start a long asynchrone query, and follow it with a short asynchrone query, the second one will finish before the first.
As stated in your reference, MARS works through "Interleaved execution". It is my understanding and my experience that from the application point of view, you feel that the result is the same as if the stuff was working in real parallel execution. If you start a long asynchrone query, and follow it with a short asynchrone query, the second one will finish before the first.
I don't believe that is guaranteed, though. The reference states "at well-defined points." Do you know what those "well-defined points" are? Is it guaranteed that a short query will finish before a long query?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Using multiple instances is usually something that developers want to avoid. In fact, you should use the same instance for multiple operations. Make the connection instance to be global so you can access it from any code-block and just play with its state (open it and close it after use each time).
Example, make this global, public:
SqlConnection conn = new SqlConnection("ConnectionS
Then, every time you need to use this connection don't forget to open and close it, or if you use it for parallel execution do not close it after all queries are executed;
conn.Open();
//run queries
conn.Close();
Let me know if anything.
Regards,
Igor