Multi threading and database connections

  • Thread starter Thread starter Marshal Antony
  • Start date Start date
M

Marshal Antony

Hi,
What is the best approach for creating database connections while using
threading to execute multiple queries in .NET?
For eg: I need to run 15 queries using threading from the same database
with minimal number of database connections.
Any suggestion is appreciated.
Thanks,
Marshal Antony
 
Hi,

If you need to run 15 queries in parallel, then you'll need 15 connections.
Anyway, you should rely on connection pooling - it will create as many
connections as needed.
 
I wish to add that strictly parallel might not be necessary. If they execute
fast enough and release connections, then ADO.NET will pool the connections
properly, so it will look like you are running 15 queries in parallel with
min # of d/b connections.

- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik



Miha Markic said:
Hi,

If you need to run 15 queries in parallel, then you'll need 15 connections.
Anyway, you should rely on connection pooling - it will create as many
connections as needed.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Marshal Antony said:
Hi,
What is the best approach for creating database connections while using
threading to execute multiple queries in .NET?
For eg: I need to run 15 queries using threading from the same database
with minimal number of database connections.
Any suggestion is appreciated.
Thanks,
Marshal Antony
 
Hi Miha,
Thanks for the reply.As far as I know connection pooling is implemented
by default in ADO.NET.
I have an issue of active connections hold up in the MySQL database after
all the threads are finished execution(sometimes 30 threads are executed
and wait all the threads are finished(join) to merge the results in a
single datatable).It is working fine with superior performace but has some
active connections hold up in the MySQL database after everything is
finished.Iam using the "using"statement in C# to make sure the connections
are garbage collected.To connect to MySQL I am using an open source MySQL
provider for .NET.

Any help in solving the issue is appreciated.
Thanks,
Marshal Antony
..NET Developer



Miha Markic said:
Hi,

If you need to run 15 queries in parallel, then you'll need 15 connections.
Anyway, you should rely on connection pooling - it will create as many
connections as needed.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Marshal Antony said:
Hi,
What is the best approach for creating database connections while using
threading to execute multiple queries in .NET?
For eg: I need to run 15 queries using threading from the same database
with minimal number of database connections.
Any suggestion is appreciated.
Thanks,
Marshal Antony
 
Hi Marshal,

Marshal Antony said:
Hi Miha,
Thanks for the reply.As far as I know connection pooling is
implemented
by default in ADO.NET.
I have an issue of active connections hold up in the MySQL database after
all the threads are finished execution(sometimes 30 threads are executed
and wait all the threads are finished(join) to merge the results in a
single datatable).It is working fine with superior performace but has some
active connections hold up in the MySQL database after everything is
finished.Iam using the "using"statement in C# to make sure the connections
are garbage collected.To connect to MySQL I am using an open source MySQL
provider for .NET.

The thing is, that disposing a connection doesn't necessarily phisically
close it (however if you don't dispose it or at least Close it it might
never really close) - this is in the hands of connection pooler.
Normally, the connection pooling settings are incorporated within connection
string and dependent on the provider (i.
I suggest you to check how does your provider manage connection pooling (I
have never worked with MySQL) and whether you can modify its behaviour.
 
Hi Miha,
Thanks for your reply.The active connections in MYSQL go away after
certain period of time automatically,so it is not a very serious problem for
me now.
So it narrow down to the provider and connection pooling.
Thanks again,
Marshal Antony
..NET Developer
 
Back
Top