Solved

VB6, ActiveX server and threads

Posted on 2000-02-25
8
696 Views
Last Modified: 2008-03-10
Hi

I want to create an ActiveX server using VB6 that keeps some open connections to an Oracle server.

Many clients will create instances of the server on the same machine in the same time.

Each client will try to get an unused connection. If all the connections are used - it will wait. If he gets a connetion - it locks it until he finishes the query.

I need the array of boolean flags(used/not used flag) to be shared for all the instances. Managed to do it by declaring the array in Moudle.

Will each instance use another thread/process (I want the queries be executed in the same time)??

Do I need to use Mutex/Shemaphore/Critical Sections to protect the access to the shared memory?

What's the meaning of the threads number in Project->Options??

Thanks,
Saar Carmi
0
Comment
Question by:saar2
8 Comments
 
LVL 3

Expert Comment

by:paulstamp
ID: 2558088
If you want all apps to access the same flags within the object then you need to set the Instancing property of your object to be be SingleUse or PublicNotCreatable. See the VB Help documentation for the Instancing property for full details.
0
 
LVL 1

Accepted Solution

by:
macu earned 300 total points
ID: 2558386
If you use a single thread (thread pool of 1), all instances will share the same global data, however object method calls will be serialized. If you use a thread pool of > 1 or thread per object, not all objects will shared the same global data (although some may in the thread pool > 1 case.)

Here's another method:

Use a thread pool and set the number of threads to the number of connections you want to allow. Have 'global' data  (in '' because the different threads won't share it) of a single boolean. Have your connection type object set the flag on creation and reset the flag on termination. Before setting the flag however, the object should check if it is already set, if it is it should not allow a connection, but can poll the flag until the object(s) it is sharing the thread with completes (and terminates.) NB, you may want to change where this flag is set/reset in case the clients won't destroy the object when they are finished with a connection. Also, you will have to decide how/whether you want the object to tell the client that a connection is not currently available.

However, doesn't MTS do all this for you? Why not use that instead?
0
 
LVL 4

Author Comment

by:saar2
ID: 2561003
How does the MTS help me?
0
 
LVL 4

Author Comment

by:saar2
ID: 2561584
Adjusted points to 300
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Author Comment

by:saar2
ID: 2561585
I decided that I don't want any client to wait - if there is no available connection I will create another one.

I thought that all the objects share the global memory so I could make a "manager" that controls the number of connection by closing some after not being used for a while.

This cannot be done with thread pool/thread per object ('cause they don't share any memory.

Any other suggestion?

0
 
LVL 1

Expert Comment

by:macu
ID: 2564124
But making use of the fact that instances on different threads do not share global memory is one way of getting around this (as described previously.) NB, the method I described is a bit flawed, you would need to have more than just a boolean globally to allow for queues of objects waiting connections, so that they will gain the connection in the correct order.

However, if you are going to create a new connection for each client, what is the question now?
0
 
LVL 4

Author Comment

by:saar2
ID: 2565899
I have read a book about MTS with VB and it solved all the problems.

Thanks.
0
 

Expert Comment

by:nuwi
ID: 7800715
Could you tell which book was it ?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now