PC Review


Reply
Thread Tools Rate Thread

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

 
 
Max2006
Guest
Posts: n/a
 
      17th Aug 2007
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






 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      17th Aug 2007
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.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
>
>
>
>
>
>

 
Reply With Quote
 
John Saunders [MVP]
Guest
Posts: n/a
 
      17th Aug 2007
"Max2006" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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]

 
Reply With Quote
 
Max2006
Guest
Posts: n/a
 
      17th Aug 2007

Does this means that TableAdapter is not thread safe?


"Max2006" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>
>
>
>
>



 
Reply With Quote
 
John Saunders [MVP]
Guest
Posts: n/a
 
      17th Aug 2007
"Max2006" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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]

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      20th Aug 2007
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.


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      22nd Aug 2007
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.


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to assign a static IP to both wired and wireless adapters? Nih Windows Vista Networking 4 30th Jan 2009 01:27 AM
Typed datasets and table table adapters components not showing inToolbox bz Microsoft Dot NET 3 10th Apr 2008 02:13 AM
Typed datasets and table table adapters components not showing inToolbox bz Microsoft Dot NET Framework 0 8th Mar 2008 11:03 PM
XP IIS 5.1, Multiple adapters, Static Internal IP, DUN Dynamic IP j_mids Windows XP Networking 0 12th Feb 2008 02:21 PM
Table adapters vs. Data adapters Chas Microsoft VB .NET 1 23rd May 2007 06:04 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 PM.