By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,365 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,365 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.Sel ect, 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


Aug 17 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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)

Max2006 wrote:
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.Sel ect, 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

Aug 17 '07 #2

P: n/a
"Max2006" <al*******@newsgroup.nospamwrote in message
news:uX**************@TK2MSFTNGP05.phx.gbl...
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.
--
John Saunders [MVP]

Aug 17 '07 #3

P: n/a

Does this means that TableAdapter is not thread safe?
"Max2006" <al*******@newsgroup.nospamwrote in message
news:uX**************@TK2MSFTNGP05.phx.gbl...
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.Sel ect, 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


Aug 17 '07 #4

P: n/a
"Max2006" <al*******@newsgroup.nospamwrote in message
news:eX**************@TK2MSFTNGP03.phx.gbl...
>
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!
--
John Saunders [MVP]

Aug 17 '07 #5

P: n/a
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.
Aug 20 '07 #6

P: n/a
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.
Aug 22 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.