<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<TITLE>Message</TITLE>
<META content="MSHTML 6.00.6000.16544" name=GENERATOR></HEAD>
<BODY>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=gmail_quote>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV lang=fr align=left><SPAN><FONT face=Arial color=#0000ff size=2>The
minimum requirement for multithreaded db access is to use a separate db
connection for every thread and transaction isolation.</FONT></SPAN></DIV>
<DIV class=im>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,255) 2px solid; MARGIN-RIGHT: 0px">
<DIV lang=fr dir=ltr align=left><SPAN></SPAN><FONT face=Arial
color=#0000ff size=2></FONT><BR>I am not sure if the database library code
is faulty or looking up the values in a thread is the
problem<BR><SPAN><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></DIV></BLOCKQUOTE></DIV>
<DIV lang=fr align=left><SPAN><FONT face=Arial color=#0000ff size=2>Some
database client libraries have problems with multithreading or have
threadsafe versions (fe. libmysql.dll is not threadsafe in the standard
version). </FONT></SPAN></DIV>
<DIV class=im>
<BLOCKQUOTE
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,255) 2px solid; MARGIN-RIGHT: 0px">
<DIV lang=fr dir=ltr align=left><SPAN></SPAN><FONT face=Arial
color=#0000ff size=2></FONT><BR>The database lookup code is in a data
module running in the main thread. Do I have to use a critical section in
data module containing the threads to the database lookup?<BR><SPAN><FONT
face=Arial color=#0000ff
size=2> </FONT></SPAN></DIV></BLOCKQUOTE></DIV>
<DIV lang=fr align=left><SPAN><FONT face=Arial color=#0000ff size=2>No. That
is trying to solve the problem in the wrong place.</FONT></SPAN></DIV>
<DIV lang=fr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV><FONT color=#888888>
<DIV lang=fr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>Ludo</FONT></SPAN></DIV></FONT></DIV><BR></BLOCKQUOTE><FONT face=Arial
color=#0000ff size=2></FONT>
<DIV><BR><BR>If I put a TCP component such as an Indy http component on that
data module, and get all the lookups to be done over the http socket, is that
likely to fix the problem, rather than calling the database lookup code in the
data module directly from the threads?<BR> <SPAN
class=328300611-03102011><FONT face=Arial color=#0000ff
size=2> </FONT></SPAN></DIV></DIV></BLOCKQUOTE>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff size=2>You
mean you have a 2nd path to your database over http? As long as you
don't use the same database connection (session) from the different threads and
are sure there are no transaction isolation issues you can use whatever
communication protocol you like. Seems complicating things
though.</FONT></SPAN></DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff size=2>Why
don't you write a data lookup class in your data module that uses it's own
Txxxconnection,TSQLTransaction and TSqlQuery and have each thread use its own
instance? Destroy after use or, when frequent data updates are needed, give it a
DisConnect method so that the number of sessions remains reasonable. If you have
a lot of threads and the number of simultanuous database sessions is an issue,
then write one lookup procedure using a criticial section but, again, using
its own database connection: enter criticial section, connect to database,
run sql, retrieve data, disconnect, exit critical section. </FONT></SPAN></DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff
size=2>Ludo</FONT></SPAN></DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=328300611-03102011><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV></BODY></HTML>