Operation is not allowed when the object is open. (VB6)

This exception occurs when you are opening a connection using an ADODB.Connection object that was previously opened. So, the solution is to close before opening. But what if this is a shared ADODB.connection which you cannot simply just close it ?

The real solution is to create a new ADODB.Connection object for each connection you are trying to make. The ideal way will be having one ADODB.connection object for each of your entity classes.

The main idea is that new connection will create a new ADODB.connection object and you don't have to close it to cater for other simultaneous connection.

For a single shared connection object (ADODB.connection) to work, you have to close the previous connection first.

A shared connection scenario is applicable to Database access to MS Access where only one connection (at a time) is allowed per exe. However, you may need simultaneous connection for databases like MSSQL, MySQL? and etc.

Check out a sample code on VB6.



Actually, the to make things easy, if you still want to use shared ADODB.connection object, and you wanted simultaneous multiple connection, you can.

If the object (ADODB.connection) is already opened, then don't open it and straight away use it to retrieve data.

But this is not encouraged because the codes will be hard to maintain and the work-flow will be messy.

Comments