Can we use static table adapters in highly concurrent web sites?

M

Max2006

Hi,

I am trying to make our business logic layer components more efficient. We
use strongly typed datasets and TableAdapters.

Is it a good idea to use a static TableAdpater to share the static instance
among all sessions?

My business logic components are like this:


[DataObject]
public static class AccountBLL
{
private static ProfileTableAdapter m_ProfileTableAdapter = null;
private static ProfileTableAdapter AccountProfileTableAdapter
{
get
{
if (m_ProfileTableAdapter == null)
m_ProfileTableAdapter = new ProfileTableAdapter();

return m_ProfileTableAdapter;
}
}

[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
public static AppDataSet.ProfileDataTable GetAllProfiles()
{
AppDataSet.ProfileDataTable dt;
dt = AccountProfileTableAdapter.GetData();
return dt;
}
}


Whole sessions within the web application are going to share a single
instance of ProfileTableAdapter because it is static. I am a bit concern in
high concurrent situations. Is it safe?

Any help would be appreciated,
Max
 
B

bruce barker

its a bad idea. you will need to add locking to your current code so
that only one call can run at a time or it will fail when concurrent
requests happen (connection is use errors).

you can still use static methods, but each method should create and
release its own tableadapter.

-- bruce (sqlwork.com)
 
J

John Saunders [MVP]

Max2006 said:
Hi,

I am trying to make our business logic layer components more efficient. We
use strongly typed datasets and TableAdapters.

Have you done some profiling that suggests that your TableAdapters are a
significant source of poor performance?

If not, then don't touch them! Never optimize where you _think_ the
performance problem is. Don't solve the wrong problem.

Especially don't touch them by making them static, which means that multiple
requests will be using the same data at the same time.
 
J

John Saunders [MVP]

Max2006 said:
Does this means that TableAdapter is not thread safe?

Of course it's not. Almost nothing _is_ thread safe! You should assume that
any class is ***not*** thread safe unless it tells you otherwise!
 
S

Steven Cheng[MSFT]

Hi Max,

Yes, as for TableAdapter classes, they're complex classes that may contain
internal fields/members that help perform the data accessing code logic,
this will make the class(its methods) become context sensitive and not
thread-safe. I agree that you should void use shared TableAdapter if
possible.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Max,

Do you have any further question on this? If so, please don't hesitate to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top