473,797 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Multi threaded app database access

Hi,

I have a multithreaded app which now needs database storage.

I am in the process of designing my Data Access Layer but and was wondering
what issues I should look for for in regards to a multi threaded app.

My app will be need to initiate access to the database from several places
in the Business logic. I'd appreaciate any advice/suggesstions on best
practices to avoid problems such as accessing the same method in the data
access layer form different parts of the business logic at the same time etc,

Thanks In Advance
Andy
Apr 24 '06 #1
5 5463
> I have a multithreaded app which now needs database storage.
I am in the process of designing my Data Access Layer but and was wondering
what issues I should look for for in regards to a multi threaded app.
Performance, resources, scalability. Look at connection pools and thread pool
My app will be need to initiate access to the database from several places
in the Business logic. I'd appreaciate any advice/suggesstions on best
practices to avoid problems such as accessing the same method in the data
access layer form different parts of the business logic at the same time etc,


It's not very good solution to block table from the business logic
perspective.
DBs have concept of ACID see there
http://www.service-architecture.com/...roperties.html or
in MSDN that allow to specyfy which level of isolation do u need to apply for
your tables. Scrutinize DB manuals to get more info about it

--
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche

Apr 24 '06 #2
Hi,

"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:0A******** *************** ***********@mic rosoft.com...
I am in the process of designing my Data Access Layer but and was
wondering
what issues I should look for for in regards to a multi threaded app.
A web app with DB access faces the very same issues, you could read some
articles about how to implement DB access in the web.
My app will be need to initiate access to the database from several places
in the Business logic. I'd appreaciate any advice/suggesstions on best
practices to avoid problems such as accessing the same method in the data
access layer form different parts of the business logic at the same time
etc,


I would keep the DB access class as a stateless class, each method receive a
ICommand that just execute using the selected way (
ExecuteReader/NonQuery/Scalar ). Also each method will create its own
connection.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Apr 24 '06 #3
Hi Ignacio,

Wouldn't I have to lock the methods in the database access class while in
use to stop them being called from elsewhere in the business logic?

Regards
Macca

"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:0A******** *************** ***********@mic rosoft.com...
I am in the process of designing my Data Access Layer but and was
wondering
what issues I should look for for in regards to a multi threaded app.


A web app with DB access faces the very same issues, you could read some
articles about how to implement DB access in the web.
My app will be need to initiate access to the database from several places
in the Business logic. I'd appreaciate any advice/suggesstions on best
practices to avoid problems such as accessing the same method in the data
access layer form different parts of the business logic at the same time
etc,


I would keep the DB access class as a stateless class, each method receive a
ICommand that just execute using the selected way (
ExecuteReader/NonQuery/Scalar ). Also each method will create its own
connection.

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Apr 24 '06 #4
Hi,

"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:B9******** *************** ***********@mic rosoft.com...
Hi Ignacio,

Wouldn't I have to lock the methods in the database access class while in
use to stop them being called from elsewhere in the business logic?


No, unless the DB class is using shared resources, which you should not.

Here is an example, this class deal with the DB comm, it does receive a
SqlCommand (which is built by the BO ).

As you can see none method use any shared resources, and a connection is
created and closed inside the method.

public class DataProvider
{
static string connString;
public static string ConnString
{
get{ return connString;}
set
{
connString = value;
}
}
static public object ExecuteScalar(S qlCommand command)
{
object returnvalue = null;
if ( connString == "")
throw new Exception("No connection string defined");
SqlConnection conn = new SqlConnection( connString);
try
{
conn.Open();
command.Connect ion = conn;
returnvalue = command.Execute Scalar();

}
catch( Exception e)
{
throw new Exception("Erro r ocurred in ExecuteScalar: commandtext: " +
command.Command Text, e);
}
finally
{
conn.Close();
}
return returnvalue;

}
static public SqlDataReader ExecuteReader(S qlCommand command)
{}
Apr 24 '06 #5
Your tsql procs may need special attention. I think a reasonable design is
to have all updates in sprocs and have selects in client code and/or in
sprocs. Most of the sql will automatically handle sync within the context
of the sql statement transaction. Sometimes, for special procs like a "test
and set" you may need to ensure correct atomic behavior with other tsql
symantics. But that is all on the sql end. Your DAL could probably be a
static class with all static methods, so you should not need any special
synchronization in general. Naturally, this may not always be true and you
may need some shared object(s) that will need to be sync'd with a lock, etc.
It all depends on what your doing.

--
William Stacey [MVP]

"Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
news:B9******** *************** ***********@mic rosoft.com...
| Hi Ignacio,
|
| Wouldn't I have to lock the methods in the database access class while in
| use to stop them being called from elsewhere in the business logic?
|
| Regards
| Macca
|
| "Ignacio Machin ( .NET/ C# MVP )" wrote:
|
| > Hi,
| >
| > "Macca" <Ma***@discussi ons.microsoft.c om> wrote in message
| > news:0A******** *************** ***********@mic rosoft.com...
| >
| > > I am in the process of designing my Data Access Layer but and was
| > > wondering
| > > what issues I should look for for in regards to a multi threaded app.
| >
| > A web app with DB access faces the very same issues, you could read
some
| > articles about how to implement DB access in the web.
| >
| > > My app will be need to initiate access to the database from several
places
| > > in the Business logic. I'd appreaciate any advice/suggesstions on best
| > > practices to avoid problems such as accessing the same method in the
data
| > > access layer form different parts of the business logic at the same
time
| > > etc,
| >
| > I would keep the DB access class as a stateless class, each method
receive a
| > ICommand that just execute using the selected way (
| > ExecuteReader/NonQuery/Scalar ). Also each method will create its own
| > connection.
| >
| >
| >
| > --
| > Ignacio Machin,
| > ignacio.machin AT dot.state.fl.us
| > Florida Department Of Transportation
| >
| >
| >
Apr 25 '06 #6

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

Similar topics

0
1853
by: Atul Kshirsagar | last post by:
I am embedding python in my C++ application. I am using Python *2.3.2* with a C++ extention DLL in multi-threaded environment. I am using SWIG-1.3.19 to generate C++ to Python interface. Now to explain it in details, 1. Python initialization and finalization is done in the *main* thread. 2. For each new thread I create a separate sub-interpreter . 3. Using PyRun_String("import myModule"...) before execution of python
0
2602
by: David | last post by:
I've installed the DBD::Proxy and RPC::PLServer modules on Windows 2000 accessing SQL Server 2000 (through an ODBC system DSN). I can interface to the database from one or more Linux boxes just fine, with the exception that the server is single threaded (i.e., when submitting a query from one script on the same or different clients, connection to the server does not occur until the connection from a different script is closed). How can I...
0
4934
by: Ganbold | last post by:
Hi, I'm new to multi-threaded programming and reading the book "Programming with POSIX Threads" and trying to understand concepts and coding. What I'm trying to do is to rewrite mysql client application (which calculates ISP dial-up customers' billing) into multi-threaded version.
5
1706
by: Rob Durant | last post by:
Hi, I have a multi-threaded application (have also tried as service - same behaviour) that runs fine on XP, but not on 2003. Symptoms are: Threads are started normally, locks acquired and released as needed, runs fine for some time, then stops - Visual Studio detects no exceptions, and I have placed break points on all the handling code to catch them. No errors / failures are logged, but child threads have all exited, and I am left...
5
1785
by: Duncan Mole | last post by:
Hi all, Does anyone know of a way to achieve multi-theaded platform invokes? I have been taking quite a performance hit using the syncronised attribute: . Cheers ---
9
2899
by: Seenu | last post by:
Is it safe to create a static function in a multi threaded application ? As an example, I have a function that logs errors ,exceptions and some informational data public static void Log(....) { // } There are multiple threads in this application that call this function. Is there any advantage if each thread creates an instance of the
9
6090
by: Stu | last post by:
Hi, I have a web service that does database access and calculations However it keeps falling over becuase its not multi threaded and each call to it is not in its own space!! I dont want to use com+ so is there any way of making it Multi threaded TIA
0
1168
by: JeffJones176 | last post by:
Hello All: I am very new to multi-threaded programming and have a need (I think) to write an application that uses multi-threaded pages. My scenario follows: My business has multiple databases, multiple websites, like a franchised business, and multiple branches that go to each website (22 branches for one website, 2 for another, etc.).
14
3414
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its libraries are suitable for multi-threaded programming. For people who are fond of portable C programming, what's the best way to go about multi-threaded programming? I've been reading up on POSIX threads a little, they seem pretty ubiquitous....
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10245
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10205
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10021
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7559
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6802
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4131
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.