Is TableAsapter thread safe?

  • Thread starter Thread starter Max2006
  • Start date Start date
M

Max2006

Hi,

In our ASP.NET application 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;
}
}


All asp.net 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 thread safe?

Any help would be appreciated,
Max
 
Hello Max,

I'm afraid to say TableAdatper is not thread safe.
It is NOT a good idea to share static TableAdatper.

Actually, Table adapter is a DBDATAADAPTER wrapped class which generated by
VS 2005.
For DbDataAdapter, only public STATIC member is thread safe. Any instance
members are not guaranteed to be thread safe.
http://msdn2.microsoft.com/en-us/library/system.data.common.dbdataadapter.as
px
[DbDataAdapter Class].

TableAdatper updates table by calling DbDataAdapter.update() method
directly. Thereby, it is also not guaranteed to be thread safe.

I'd like to suggest creating a new TableAdatper instance for each time you
need it, rather than sharing it among all sessions.

Hope this helps. Please let me know if you have any more concern. We are
glad to assist you.
Have a great day.

Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
All asp.net 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 thread safe?

So what if it is.

You can have 2+ components that are each thread-safe but in combination are
not thread-safe. The thread-safety factor is working at the wrong level.
Each time you move from state-to-state, you want it so that all components
within the state change as one unit, rathe like a database transaction.
Making each component thread-safe does not gurantee that.

Stephen Howe
 
Hello Max,

This is Wen Yuan again. I haven't heard from you a couple of days.
Do you meet any further issue? I just want to check if you have any more
concern.
If so, please feel free to let me know. We are glad to assist you.

Have a great day.

Best regards,
Wen Yuan
Microsoft Online Community Support
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Hi Wen,

Thank you for help. I cahnge the BLL pattern within our application so BLL
methods create a new TableAdapter.

Thank you very much,
Max
 
Back
Top