473,403 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Object doesn't create seperate instances for each session

Hi NG,

I have an asp.net project that uses an vb6 com object for some
database-manipulation (I cannot rewrite it in .net, sorry, its not my
decision).

I want it to be instanciated seperately for each session, so that three
users can connect to three different databases. But I get crazy because:

-With interop all users share one instance - pure chaos (the instance is
guilty for the whole app grrrrrmmmmml...)
-integrated it in global.asax and using the static objects collection forces
me to change the whole code to get access and I have to be sure to write
correct code from my mind because there is no code completion...

Is there a way to have the object in my project with interop and having it
for each session seperatly and not about the whole application?
thx,
best regards,

Markus Prediger
Nov 19 '05 #1
2 2099
your analysis is incorrect, interop does not force single instance (only
shared or static variables cause this effect)

vb6 com objects are apartment model com objects, and not supported by
default with asp.net (which is designed for free threaded objects). an
apartment model objects must be called from the same thread that created
them, vb6 com objects store state info in thread local storage, so this rule
is very important with them.

you can use the aspcompat flag (required to call vb6 com objects), which
forces a calls to an sta object to use a thread from the STA pool. if you
stick an sta object in session (with aspcompat on), then that thread is
bound to the session. the same thread will be used to service request using
that session. thus all calls to the session object use the same thread. if
you create multiple instances of an sta object and store in different
sessions, each instance will have a dedicated thread.

the best performance would be to create and destroy your vb6 com object on
each page. then you only lose thread agility, as request threads come from
the STA pool.

to recap, set aspcompat on every page that references your vb6 component. do
not store the object in a shared variable, or a module level variable

note: sta com objects are not supported by webservices, you need to write
your own sta threading handlers for this.

-- bruce (sqlwork.com)


"Markus Prediger" <prediger @itb-web.de> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi NG,

I have an asp.net project that uses an vb6 com object for some
database-manipulation (I cannot rewrite it in .net, sorry, its not my
decision).

I want it to be instanciated seperately for each session, so that three
users can connect to three different databases. But I get crazy because:

-With interop all users share one instance - pure chaos (the instance is
guilty for the whole app grrrrrmmmmml...)
-integrated it in global.asax and using the static objects collection
forces
me to change the whole code to get access and I have to be sure to write
correct code from my mind because there is no code completion...

Is there a way to have the object in my project with interop and having it
for each session seperatly and not about the whole application?
thx,
best regards,

Markus Prediger

Nov 19 '05 #2
Hi Bruce,

very thank you for your Help!!!

you are completely right, I yesterday recognized that the only way to use it
with seperate instances is to declare it in the frontend of global.asax
(<object id=...) and to use it with
Session.StaticObjects("com-instance").method. Then it works perfect, but
with absolutly no help (code completion etc.) from the IDE. The
aspcompat-attribute I've already inserted a long time ago, hoping it would
work so... ;-( . I'm a little bit sad that M$ did not integrate this more
developer-frienly...
Ok everybody says to rewrite everything in .net, but we both do not have
time and money to rewrite this component AND put it into the other 12 or 15
vb6-applications for client pcs that use it. Maybe in 5 or 10 years we will
have it, but not at the moment.

To your idea: "the best performance would be to create and destroy your vb6
com object on each page." I also tried but the object is for the whole
database connection to mssql server and to have it opened and closed for
each request wouldn't be very performant.

But I have another question, because I have another object that I really
instanciate for one request (in one *.aspx.vb file) and then kill again (it
is included with interop). If two users do the same page request, will they
also have the same instances? With your description, it would be so. So for
having clean code, I have to instance it, put it into the session
(session.add) and use this instance (again no code completion any more). How
will I kill this instance in the end??

mfg and thx again,

Markus Prediger
"Bruce Barker" <br******************@safeco.com> schrieb im Newsbeitrag
news:uy**************@TK2MSFTNGP14.phx.gbl...
your analysis is incorrect, interop does not force single instance (only
shared or static variables cause this effect)

vb6 com objects are apartment model com objects, and not supported by
default with asp.net (which is designed for free threaded objects). an
apartment model objects must be called from the same thread that created
them, vb6 com objects store state info in thread local storage, so this rule
is very important with them.

you can use the aspcompat flag (required to call vb6 com objects), which
forces a calls to an sta object to use a thread from the STA pool. if you
stick an sta object in session (with aspcompat on), then that thread is
bound to the session. the same thread will be used to service request using
that session. thus all calls to the session object use the same thread. if
you create multiple instances of an sta object and store in different
sessions, each instance will have a dedicated thread.

the best performance would be to create and destroy your vb6 com object on
each page. then you only lose thread agility, as request threads come from
the STA pool.

to recap, set aspcompat on every page that references your vb6 component. do
not store the object in a shared variable, or a module level variable

note: sta com objects are not supported by webservices, you need to write
your own sta threading handlers for this.

-- bruce (sqlwork.com)


"Markus Prediger" <prediger @itb-web.de> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi NG,

I have an asp.net project that uses an vb6 com object for some
database-manipulation (I cannot rewrite it in .net, sorry, its not my
decision).

I want it to be instanciated seperately for each session, so that three
users can connect to three different databases. But I get crazy because:

-With interop all users share one instance - pure chaos (the instance is
guilty for the whole app grrrrrmmmmml...)
-integrated it in global.asax and using the static objects collection
forces
me to change the whole code to get access and I have to be sure to write
correct code from my mind because there is no code completion...

Is there a way to have the object in my project with interop and having it
for each session seperatly and not about the whole application?
thx,
best regards,

Markus Prediger


Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: TonyB | last post by:
Hi, I've searched the group and need more information and guidance on this issue I need to resolve next week. I work for the local school system and I am working on a way to parse a CSV file of...
9
by: Jimmy Cerra | last post by:
I am a little confused how the memory for objects is allocated in JavaScript. David Flanagan, in "JavaScript: The Definitive Guide," states that each property of a class takes up memory space when...
2
by: Alan Kordy | last post by:
I am new to OOP and C#, and I am just a beginner to learn those stuff. Hopefully someone can give me some guidance about object design. Let say, I want to create a class called Book. This class...
2
by: davidw | last post by:
As I asked in last post, I want to put some logic in a object and all my webcontrol instance will access that object, the object is responsed to retrieve data from database if the data has not been...
4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
12
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. ...
11
by: syssyx | last post by:
I have a "CurrentUser" object in session that I want to access from each page of a vb.net website. I can successfully access everything if I include the following at the start of each pageload: ...
6
by: burningodzilla | last post by:
Hi all - I'm preparing to dive in to more complex application development using javascript, and among other things, I'm having a hard time wrapping my head around an issues regarding "inheritance"...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.