Problems setting ActiveConnection in ADODB.Command 
Author Message
 Problems setting ActiveConnection in ADODB.Command

Hi,
I'm trying to access a DB2/400 via ADO from VB. I would only like to
have one connection for several Commands.
The manual says to call 'cmd.ActiveConnection = conn', which I did not
yet succeed to get to run:
- Calling 'cmd.ActiveConnection = conn' returns a runtime error 3001:
'Argumente sind vom falschen Typ, liegen ausserhalb des
Gueltigkeitsbereichs oder sind miteinander unvereinbar' (arguments have
wrong type, ...).
- Calling 'set cmd.ActiveConnection = conn' (as I always do when
assigning objects) returns the same error.
- Calling 'cmd.ActiceConnection = conn.ConnectionString' works, but
opens a new connection, which is not what I want (for performance and
some other reasons).

The manual says, ActiveConnection is of type String (which explains why
my third way does not produce an error), on the other hand it is
assigned to a Connection object. This is all very confusing.

Could somebody please help me?

THX,
Manfred.

PS: I'm using VB 6.0 (SP4), V4R5, C/A 4.4.0

--
-----------------------------------------------------------------
  Dipl.-Inf. Manfred Weigl            Branchware & Partner GmbH
  Tel. : +49 911 27069-46             Schnieglinger Strasse 118
  Fax  : +49 911 27069-49             90425 Nuernberg

-----------------------------------------------------------------



Sat, 27 Sep 2003 18:18:11 GMT  
 Problems setting ActiveConnection in ADODB.Command
Try to Set something like this, it works in my app's ....

Dim mCnn as ADODB.Connection
Dim mCmd as ADODB.Command

mCnn.Open = "connection string ..."
...
<some other code>
...
' Set the currently open connection to Command Object
Set mCmd = New ADODB.Command
Set mCmd.ActiveConnection = mCnn
mCmd.Execute .... etc...
...
Sets or returns a String containing the definition for a connection or a
Connection object. Default is a Null object reference.

For Command objects, the ActiveConnection property is read/write. If you
attempt to call the Execute method on a Command object before setting this
property to an open Connection object or valid connection string, an error
occurs.

Setting the ActiveConnection property to Nothing disassociates the Command
object from the current Connection and causes the provider to release any
associated resources on the data source. You can then associate the Command
object with the same or another Connection object. Some providers allow you
to change the property setting from one Connection to another, without
having to first set the property to Nothing. If the Parameters collection of
the Command object contains parameters supplied by the provider, the
collection is cleared if you set the ActiveConnection property to Nothing or
to another Connection object. If you manually create Parameter objects and
use them to fill the Parameters collection of the Command object, setting
the ActiveConnection property to Nothing or to another Connection object
leaves the Parameters collection intact.
Closing the Connection object with which a Command object is associated sets
the ActiveConnection property to Nothing. Setting this property to a closed
Connection object generates an error.

Branimir Bajt , MCSE
Incendo GmbH, IT Enterprise Systems & Consulting, Croatia
www.incendo.hr



Sat, 27 Sep 2003 19:38:50 GMT  
 Problems setting ActiveConnection in ADODB.Command

Quote:

> Hi,
> I'm trying to access a DB2/400 via ADO from VB. I would only like to
> have one connection for several Commands.
> The manual says to call 'cmd.ActiveConnection = conn', which I did not
> yet succeed to get to run:
> - Calling 'cmd.ActiveConnection = conn' returns a runtime error 3001:
> 'Argumente sind vom falschen Typ, liegen ausserhalb des
> Gueltigkeitsbereichs oder sind miteinander unvereinbar' (arguments have
> wrong type, ...).
> - Calling 'set cmd.ActiveConnection = conn' (as I always do when
> assigning objects) returns the same error.
> - Calling 'cmd.ActiceConnection = conn.ConnectionString' works, but
> opens a new connection, which is not what I want (for performance and
> some other reasons).

> The manual says, ActiveConnection is of type String (which explains why
> my third way does not produce an error), on the other hand it is
> assigned to a Connection object. This is all very confusing.

> Could somebody please help me?

> THX,
> Manfred.

> PS: I'm using VB 6.0 (SP4), V4R5, C/A 4.4.0

Hi again,

thanks for your response, Branimir, but this did not help me. I had
already tried out everything you suggest before, but nothing worked.

I suppose I've forgotten to mention an important detail: I have a new
OLE component which should use a connection from outside;
i.e.
I have component A which opens the connection;
A creates a new component B and gives its connection to B;
B uses the connection (or: should use!).
I've already tried to let B create/open a new connection using A's
connection's ConnectionString, and everything works fine. (But I do not
want to open a new connection!)
I've also tried to let B call mConnection.execute("SELECT ..") on A's
connection; this works, too.
But I CANNOT assign A's connection to a stored procedure's
ActiveConnection!

It seems to me as if VB has problems in correctly copying the connection
object to the new address space. Are there any experiences/solutions to
this problems?

TIA,
Manfred.

-----------------------------------------------------------------
  Dipl.-Inf. Manfred Weigl            Branchware & Partner GmbH
  Tel. : +49 911 27069-46             Schnieglinger Strasse 118
  Fax  : +49 911 27069-49             90425 Nuernberg

-----------------------------------------------------------------



Mon, 20 Oct 2003 16:48:35 GMT  
 Problems setting ActiveConnection in ADODB.Command

I don't know the answer, but just a thought in case ...
    ... Have you fiddled with the ByVal / ByRef declaration of the function
used to pass the Connection from one component to the other.

Cheers,
Neil


Quote:

> > Hi,
> > I'm trying to access a DB2/400 via ADO from VB. I would only like to
> > have one connection for several Commands.
> > The manual says to call 'cmd.ActiveConnection = conn', which I did not
> > yet succeed to get to run:
> > - Calling 'cmd.ActiveConnection = conn' returns a runtime error 3001:
> > 'Argumente sind vom falschen Typ, liegen ausserhalb des
> > Gueltigkeitsbereichs oder sind miteinander unvereinbar' (arguments have
> > wrong type, ...).
> > - Calling 'set cmd.ActiveConnection = conn' (as I always do when
> > assigning objects) returns the same error.
> > - Calling 'cmd.ActiceConnection = conn.ConnectionString' works, but
> > opens a new connection, which is not what I want (for performance and
> > some other reasons).

> > The manual says, ActiveConnection is of type String (which explains why
> > my third way does not produce an error), on the other hand it is
> > assigned to a Connection object. This is all very confusing.

> > Could somebody please help me?

> > THX,
> > Manfred.

> > PS: I'm using VB 6.0 (SP4), V4R5, C/A 4.4.0

> Hi again,

> thanks for your response, Branimir, but this did not help me. I had
> already tried out everything you suggest before, but nothing worked.

> I suppose I've forgotten to mention an important detail: I have a new
> OLE component which should use a connection from outside;
> i.e.
> I have component A which opens the connection;
> A creates a new component B and gives its connection to B;
> B uses the connection (or: should use!).
> I've already tried to let B create/open a new connection using A's
> connection's ConnectionString, and everything works fine. (But I do not
> want to open a new connection!)
> I've also tried to let B call mConnection.execute("SELECT ..") on A's
> connection; this works, too.
> But I CANNOT assign A's connection to a stored procedure's
> ActiveConnection!

> It seems to me as if VB has problems in correctly copying the connection
> object to the new address space. Are there any experiences/solutions to
> this problems?

> TIA,
> Manfred.

> -----------------------------------------------------------------
>   Dipl.-Inf. Manfred Weigl            Branchware & Partner GmbH
>   Tel. : +49 911 27069-46             Schnieglinger Strasse 118
>   Fax  : +49 911 27069-49             90425 Nuernberg

> -----------------------------------------------------------------



Tue, 21 Oct 2003 05:24:37 GMT  
 Problems setting ActiveConnection in ADODB.Command
Below is a snippet from one of the samples at
http://www.ibm.com/servers/eserver/iseries/clientaccess/oledb/ (find the
VB 5.0 SQL sample).  PARTQRY2 and PARTQRYu are both ADO Command objects
and they use the same connection object.

------------------------------------------------------------------
'{{DA400_SQL_BEGIN}}
Public PARTQRY2 As New ADODB.Command
Public PARTQRYADATA As ADODB.Recordset
Public PARTQRY2DATA As ADODB.Recordset
Public PARTQRYu As New ADODB.Command
'{{DA400_SQL_END}}

Dim EndOfDeclares As String 'keeps comments from floating
Public Sub Connect()
'NOTE - The Toolkit will add and remove code between markers
'{{DA400_CONNECTS_BEGIN}}
S1056967.Open "Provider=IBMDA400;Data Source=mysystem;", "", ""
'{{DA400_CONNECTS_END}}
End Sub
Public Sub Prepare()
'NOTE - The Toolkit will add and remove code between markers
'{{DA400_PROCEDURE_PREPARES_BEGIN}}
'{{DA400_PROCEDURE_PREPARES_END}}

'{{DA400_SQL_PREPARES_BEGIN}}
Set PARTQRY2.ActiveConnection = S1056967
PARTQRY2.CommandText = "select * from ACTIVEXSDK.parts where partno = ?"
PARTQRY2.Parameters.Refresh
PARTQRY2.Prepared = True
Set PARTQRYu.ActiveConnection = S1056967
PARTQRYu.CommandText = "UPDATE ACTIVEXSDK.PARTS SET PARTQY = ? where
PARTNO = ?"
PARTQRYu.Parameters.Refresh
PARTQRYu.Prepared = True

'{{DA400_SQL_PREPARES_END}}
End Sub

Jon

Quote:

> Hi,
> I'm trying to access a DB2/400 via ADO from VB. I would only like to
> have one connection for several Commands.
> The manual says to call 'cmd.ActiveConnection = conn', which I did not
> yet succeed to get to run



Tue, 21 Oct 2003 22:46:06 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Problems setting ActiveConnection in ADODB.Command

2. Set ADODB.Command.ActiveConnection = Conn

3. Difference between .ActiveConnection and SET .ActiveConnection?

4. Setting the ActiveConnection property of a Command Object (ADO 2.7)

5. Set {command object}.ActiveConnection = fails sporadically

6. How to set DbGrid datasource to a recordset created w/ADODB.Command

7. Command.activeconnection vs connection.open

8. Command.ActiveConnection returning strange error

9. Problem creating ADODB.command object in asp.

10. ADODB.Command - ReturnValue parameter problem

11. what is wrong ? I want set rec.activeconnection

12. i want set rec.activeconnection to connection from com+

 

 
Powered by phpBB® Forum Software