Hi.
Just trying to find out the best approach as I beleive it might give me
problems later on down the road.
I have an ASP.NET application which references a shared database class which
contains methods for serialising and de-serialising objects to the database
storage. I put this as a shared class as multiple web clients will be using
the class to store and retreive data, the problem I'm haivng now is that I
think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name and
then some funcitons which execute requests against the table name, however
client A could be looking at table1 and client B will be looking at table2.
Now would the best approach be to use a SyncLock on the class before I run
the setting of the varibles and functions or get each client to initiate the
class with a Dim myClass as New MyClass ? What would be the best approach,
bering in mind that one clients requests may take a little while and the
Synclock would lock the class until this has completed and at this point we
may have 100 - 200 requests ???
An example being..............
Public MyClass
private shared TableName as string
public shared function SetTableName(s as String)
TableName = s
end function
public shared function DoSomething
Dim SQLString = "SELECT * from " + TableName
end function
End Class
Would I just use
SyncLock GetType(MyClass)
MyClass.SetTableName = "Table1"
MyClass.DoSomething
End Synclokc
or
Dim mc as New MyClass
MyClass.SetTableName = "Table1"
MyClass.DoSomething
Thanks in advance. 6 1839
Hi,
Why would you want to share a class between several request threads?
Most managed dataproviders have support for connection-pooling, this cuts
down the cost of creating a database connection dramatically. It is not
reccommended to open a connection when the application starts and use this
for all database access.
For each web request, create your database object, open a connection, do
your stuff, close the connection then dispose of the database object. Each
request has its own set of data and you avoid threading issues.
Chris
"Paul" <pa******************@vectra-it.co.uk> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl... Hi.
Just trying to find out the best approach as I beleive it might give me problems later on down the road.
I have an ASP.NET application which references a shared database class
which contains methods for serialising and de-serialising objects to the
database storage. I put this as a shared class as multiple web clients will be
using the class to store and retreive data, the problem I'm haivng now is that I think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name
and then some funcitons which execute requests against the table name, however client A could be looking at table1 and client B will be looking at
table2. Now would the best approach be to use a SyncLock on the class before I run the setting of the varibles and functions or get each client to initiate
the class with a Dim myClass as New MyClass ? What would be the best approach, bering in mind that one clients requests may take a little while and the Synclock would lock the class until this has completed and at this point
we may have 100 - 200 requests ???
An example being..............
Public MyClass private shared TableName as string
public shared function SetTableName(s as String) TableName = s end function
public shared function DoSomething Dim SQLString = "SELECT * from " + TableName end function
End Class
Would I just use
SyncLock GetType(MyClass) MyClass.SetTableName = "Table1" MyClass.DoSomething End Synclokc
or
Dim mc as New MyClass MyClass.SetTableName = "Table1" MyClass.DoSomething Thanks in advance.
Hi,
Why would you want to share a class between several request threads?
Most managed dataproviders have support for connection-pooling, this cuts
down the cost of creating a database connection dramatically. It is not
reccommended to open a connection when the application starts and use this
for all database access.
For each web request, create your database object, open a connection, do
your stuff, close the connection then dispose of the database object. Each
request has its own set of data and you avoid threading issues.
Chris
"Paul" <pa******************@vectra-it.co.uk> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl... Hi.
Just trying to find out the best approach as I beleive it might give me problems later on down the road.
I have an ASP.NET application which references a shared database class
which contains methods for serialising and de-serialising objects to the
database storage. I put this as a shared class as multiple web clients will be
using the class to store and retreive data, the problem I'm haivng now is that I think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name
and then some funcitons which execute requests against the table name, however client A could be looking at table1 and client B will be looking at
table2. Now would the best approach be to use a SyncLock on the class before I run the setting of the varibles and functions or get each client to initiate
the class with a Dim myClass as New MyClass ? What would be the best approach, bering in mind that one clients requests may take a little while and the Synclock would lock the class until this has completed and at this point
we may have 100 - 200 requests ???
An example being..............
Public MyClass private shared TableName as string
public shared function SetTableName(s as String) TableName = s end function
public shared function DoSomething Dim SQLString = "SELECT * from " + TableName end function
End Class
Would I just use
SyncLock GetType(MyClass) MyClass.SetTableName = "Table1" MyClass.DoSomething End Synclokc
or
Dim mc as New MyClass MyClass.SetTableName = "Table1" MyClass.DoSomething Thanks in advance.
You should not keep tablenames in the shared variables. It's OK to have the
methods shared, but you'll need to have instance variables as well, and
allow the application to create a new instance for each table access.
"Paul" <pa******************@vectra-it.co.uk> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl... Hi.
Just trying to find out the best approach as I beleive it might give me problems later on down the road.
I have an ASP.NET application which references a shared database class
which contains methods for serialising and de-serialising objects to the
database storage. I put this as a shared class as multiple web clients will be
using the class to store and retreive data, the problem I'm haivng now is that I think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name
and then some funcitons which execute requests against the table name, however client A could be looking at table1 and client B will be looking at
table2. Now would the best approach be to use a SyncLock on the class before I run the setting of the varibles and functions or get each client to initiate
the class with a Dim myClass as New MyClass ? What would be the best approach, bering in mind that one clients requests may take a little while and the Synclock would lock the class until this has completed and at this point
we may have 100 - 200 requests ???
An example being..............
Public MyClass private shared TableName as string
public shared function SetTableName(s as String) TableName = s end function
public shared function DoSomething Dim SQLString = "SELECT * from " + TableName end function
End Class
Would I just use
SyncLock GetType(MyClass) MyClass.SetTableName = "Table1" MyClass.DoSomething End Synclokc
or
Dim mc as New MyClass MyClass.SetTableName = "Table1" MyClass.DoSomething Thanks in advance.
You should not keep tablenames in the shared variables. It's OK to have the
methods shared, but you'll need to have instance variables as well, and
allow the application to create a new instance for each table access.
"Paul" <pa******************@vectra-it.co.uk> wrote in message
news:uK**************@TK2MSFTNGP12.phx.gbl... Hi.
Just trying to find out the best approach as I beleive it might give me problems later on down the road.
I have an ASP.NET application which references a shared database class
which contains methods for serialising and de-serialising objects to the
database storage. I put this as a shared class as multiple web clients will be
using the class to store and retreive data, the problem I'm haivng now is that I think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name
and then some funcitons which execute requests against the table name, however client A could be looking at table1 and client B will be looking at
table2. Now would the best approach be to use a SyncLock on the class before I run the setting of the varibles and functions or get each client to initiate
the class with a Dim myClass as New MyClass ? What would be the best approach, bering in mind that one clients requests may take a little while and the Synclock would lock the class until this has completed and at this point
we may have 100 - 200 requests ???
An example being..............
Public MyClass private shared TableName as string
public shared function SetTableName(s as String) TableName = s end function
public shared function DoSomething Dim SQLString = "SELECT * from " + TableName end function
End Class
Would I just use
SyncLock GetType(MyClass) MyClass.SetTableName = "Table1" MyClass.DoSomething End Synclokc
or
Dim mc as New MyClass MyClass.SetTableName = "Table1" MyClass.DoSomething Thanks in advance.
Paul:
You should seriously consider redesigning your data access class so it
is not shared. Unless you are purposefully trying to limit the number
of connections (which can be done another way) or restrict the amount
of database activity from your app, it's not worth the pain of writing
safe multithreaded code and the scalability limitations to serialize
all those requests through one object instance.
HTH,
--
Scott http://www.OdeToCode.com
On Fri, 30 Apr 2004 17:09:39 +0100, "Paul"
<pa******************@vectra-it.co.uk> wrote: Hi.
Just trying to find out the best approach as I beleive it might give me problems later on down the road.
I have an ASP.NET application which references a shared database class which contains methods for serialising and de-serialising objects to the database storage. I put this as a shared class as multiple web clients will be using the class to store and retreive data, the problem I'm haivng now is that I think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name and then some funcitons which execute requests against the table name, however client A could be looking at table1 and client B will be looking at table2. Now would the best approach be to use a SyncLock on the class before I run the setting of the varibles and functions or get each client to initiate the class with a Dim myClass as New MyClass ? What would be the best approach, bering in mind that one clients requests may take a little while and the Synclock would lock the class until this has completed and at this point we may have 100 - 200 requests ???
An example being..............
Public MyClass private shared TableName as string
public shared function SetTableName(s as String) TableName = s end function
public shared function DoSomething Dim SQLString = "SELECT * from " + TableName end function
End Class
Would I just use
SyncLock GetType(MyClass) MyClass.SetTableName = "Table1" MyClass.DoSomething End Synclokc
or
Dim mc as New MyClass MyClass.SetTableName = "Table1" MyClass.DoSomething Thanks in advance.
Paul:
You should seriously consider redesigning your data access class so it
is not shared. Unless you are purposefully trying to limit the number
of connections (which can be done another way) or restrict the amount
of database activity from your app, it's not worth the pain of writing
safe multithreaded code and the scalability limitations to serialize
all those requests through one object instance.
HTH,
--
Scott http://www.OdeToCode.com
On Fri, 30 Apr 2004 17:09:39 +0100, "Paul"
<pa******************@vectra-it.co.uk> wrote: Hi.
Just trying to find out the best approach as I beleive it might give me problems later on down the road.
I have an ASP.NET application which references a shared database class which contains methods for serialising and de-serialising objects to the database storage. I put this as a shared class as multiple web clients will be using the class to store and retreive data, the problem I'm haivng now is that I think multiple threads are overwritting the data.
In the database class its has some variables that store the tables name and then some funcitons which execute requests against the table name, however client A could be looking at table1 and client B will be looking at table2. Now would the best approach be to use a SyncLock on the class before I run the setting of the varibles and functions or get each client to initiate the class with a Dim myClass as New MyClass ? What would be the best approach, bering in mind that one clients requests may take a little while and the Synclock would lock the class until this has completed and at this point we may have 100 - 200 requests ???
An example being..............
Public MyClass private shared TableName as string
public shared function SetTableName(s as String) TableName = s end function
public shared function DoSomething Dim SQLString = "SELECT * from " + TableName end function
End Class
Would I just use
SyncLock GetType(MyClass) MyClass.SetTableName = "Table1" MyClass.DoSomething End Synclokc
or
Dim mc as New MyClass MyClass.SetTableName = "Table1" MyClass.DoSomething Thanks in advance. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Chuck Ritzke |
last post by:
I keep asking myself this question as I write class modules. What's the
best/smartest/most efficient way to send a large object back and forth to a
class module?
For example, say I have a data...
|
by: D Witherspoon |
last post by:
I am developing a Windows Forms application in VB.NET that will use .NET
remoting to access the data tier classes.
A very simple way I have come up with is by creating typed (.xsd) datasets.
For...
|
by: Paul |
last post by:
Hi.
Just trying to find out the best approach as I beleive it might give me
problems later on down the road.
I have an ASP.NET application which references a shared database class which...
|
by: epigram |
last post by:
I'm creating a data-centric asp.net application that will be using SQL
Server 2000. I'm looking for some articles, design tips, etc. to help me
decide how I should design my application. I...
|
by: Keith G. Murphy |
last post by:
I'm trying to get a feel for what most people are doing or consider best
practice.
Given a mod_perl application talking to a PostgreSQL database on the
same host, where different users are...
|
by: Sam |
last post by:
Hi,
I have a serious issue using multithreading. A sample application
showing my issue can be downloaded here:
http://graphicsxp.free.fr/WindowsApplication11.zip
The problem is that I need to...
|
by: andrea |
last post by:
Sorry for the stupid question, I know, but sometimes is necessary starts
from the basic.
I don't know how to pass the result of a method generated from a DAL class
to a BL class
returning the...
|
by: Rex |
last post by:
Hi All - I have a question that I think MIGHT be of interest to a
number of us developers. I am somewhat new to VIsual Studio 2005 but
not new to VB. I am looking for ideas about quick and...
|
by: =?Utf-8?B?bW9mbGFoZXJ0eQ==?= |
last post by:
In VB6, we created a number of ActiveX DLLs that all shared a similar
interface. The main application would load these in dynamically (late-bound.)
This worked well for our situation because we...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
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...
| |