473,387 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Multithreaded and SQL connections

cj
I have a multithreaded transaction processing app that now needs to
write to a sql db. I assume I will have to make the connection in the
main program and then each thread/transaction would create it's own
command and execute it? Is this correct?
Apr 26 '07 #1
4 3674
cj <cj@nospam.nospamwrote in news:uc**************@TK2MSFTNGP06.phx.gbl:
I have a multithreaded transaction processing app that now needs to
write to a sql db. I assume I will have to make the connection in the
main program and then each thread/transaction would create it's own
command and execute it? Is this correct?
Each thread typically has it's own connection to the database... because
connections can only process one command at a time. If you share one
connection across threads, you're going to bottleneck your application.
Apr 26 '07 #2
cj
In this app a thread is created to handle an incomming TCP/IP
connection/request. Part of processing this request currently involves
making a web request to a webserver. After the web server responds and
a bit of extra manipulation is done the thread responds to the TCP/IP
client and terminates.

The web server is being replaced by a stored procedure. Since speed
through the web server is a problem--these threads should live no longer
than 5 seconds. I don't think we can afford to make a seperate
connection to the sql server in each thread.

What do you think?
Spam Catcher wrote:
cj <cj@nospam.nospamwrote in news:uc**************@TK2MSFTNGP06.phx.gbl:
>I have a multithreaded transaction processing app that now needs to
write to a sql db. I assume I will have to make the connection in the
main program and then each thread/transaction would create it's own
command and execute it? Is this correct?

Each thread typically has it's own connection to the database... because
connections can only process one command at a time. If you share one
connection across threads, you're going to bottleneck your application.
Apr 26 '07 #3
cj <cj@nospam.nospamwrote in news:OQ**************@TK2MSFTNGP03.phx.gbl:
The web server is being replaced by a stored procedure. Since speed
through the web server is a problem--these threads should live no longer
than 5 seconds. I don't think we can afford to make a seperate
connection to the sql server in each thread.

What do you think?
Should be fine - .NET actually uses a connection pool to handle database
connections.

After a connection has been opened an a command processed, the connection
gets placed into the connection pool. After 30 seconds of idle time (or
perhaps longer) the connection is terminated.

So if you have several requests requiring connections, it'll fetch a pre-
existing connection from the pool, if non-exists a new connection is
created.

http://samples.gotdotnet.com/quickst...nectionpooling
..aspx

http://www.ondotnet.com/pub/a/dotnet.../connpool.html
Apr 26 '07 #4
cj
I've written it to make the connection in each thread as per your advise
and some info I've been able to find. They aren't ready for me to put
it into production now but I have tested the response time and it seems ok.

Spam Catcher wrote:
cj <cj@nospam.nospamwrote in news:OQ**************@TK2MSFTNGP03.phx.gbl:
>The web server is being replaced by a stored procedure. Since speed
through the web server is a problem--these threads should live no longer
than 5 seconds. I don't think we can afford to make a seperate
connection to the sql server in each thread.

What do you think?

Should be fine - .NET actually uses a connection pool to handle database
connections.

After a connection has been opened an a command processed, the connection
gets placed into the connection pool. After 30 seconds of idle time (or
perhaps longer) the connection is terminated.

So if you have several requests requiring connections, it'll fetch a pre-
existing connection from the pool, if non-exists a new connection is
created.

http://samples.gotdotnet.com/quickst...nectionpooling
.aspx

http://www.ondotnet.com/pub/a/dotnet.../connpool.html
Apr 26 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Google Mike | last post by:
I want to prepare some training for some new employees regarding the topic of multithreaded socket services implemented in PHP. I've been able to implement this with my own design, but I'd like to...
2
by: pradyumna | last post by:
In Project settins - C/C++ - Code Generation, what is the difference between the option "Multithreaded" and "Multithreaded DLL". I understand that on selecting multithreaded option, single and...
7
by: Sidd | last post by:
Hi, I tried finding and example of multithreaded client-serve program in python. Can any one please tell me how to write a multithreaded client-server programn in python such that 1.It can handle...
5
by: Mark Harrison | last post by:
I'm looking for feedback from anybody who has used pg in a multi-threaded program, particularly one in which several threads each open a database connection. It's documented to work in that...
2
by: Alan Kemp | last post by:
Hi, I have a problem that is half python, half design. I have a multithreaded network server working, each client request spawns a new thread which deals with that client for as long as it is...
6
by: Stephen Carson | last post by:
I'm trying to build a Web Service that will kick off threads as logging requests come in. These threads will then log to the database. I have been able to make a simple Web Service. I have been...
2
by: NaeiKinDus | last post by:
Hi there :) I'm trying to code a webserver running under WinXP, multithreaded, etc... The creation of my threads, the handles, everything works fine except this : the WSAEventSelect. The...
39
by: cj | last post by:
I have a 2005 TCP/IP server that creates a new thread to handle each incoming TCP/IP request. Once the request has been answered by the thread the TCP/IP socket is disconnected and the sub/thread...
1
by: JohnH | last post by:
Hi, In my application which has two or more threads calling web service or just HttpWebRequest I am seeing some HTTP 400 errors retrun in the response. All the calls are going through the same ISA...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.