Set ADODB.Command.ActiveConnection = Conn 
Author Message
 Set ADODB.Command.ActiveConnection = Conn

I have a problem. (Surprise, surprise !)

I have a code like this :

Dim cmd As ADODB.Command
Dim conn As ADODB.Connection

Set cmd = new ADODB.Command
cmd.CommandText = "GetPublisherDetail"
cmd.CommandType = adCmdStoredProc

cmd.Parameters.Append cmd.CreateParameter("PublisherId", adInteger, adParamInput, , varPublisherId)

conn.Open strconnect
Set cmd.ActiveConnection = conn
..

Of course it's not working. I traced the code and it fails on the
"Set cmd.ActiveConnection = conn".

The conn.Errors collection contains those two errors:
        [Microsoft][ODBC SQL Server Driver][SQL Server]Changed database context to 'xxx'.
        [Microsoft][ODBC SQL Server Driver][SQL Server]Changed language setting to us_english.

And the cmd.ActiveConnection is not set.

Does anyone have any idea what could be wrong?

In case it matters.
The code is in a COM object.

Erm, actualy in two. The first one creates and fills the cmd, then creates the other one and passes the cmd.
The second one creates conn and sets the activeconnection property of cmd and opens a recordset.
I tried to pass the cmd both byRef and byVal :

Public Function GetDisconnectedRecordSetFromCommand _
    ( _
    ByRef cmd As ADODB.Command, _
    ByRef rst As ADODB.Recordset _
    ) As Variant

Thanks for any insight, Jenda
P.S.: CC will be appreciated.



Mon, 03 Nov 2003 23:25:41 GMT  
 Set ADODB.Command.ActiveConnection = Conn
Don't use Set for the activeconnection.
Here is a simple example:
Dim cn As Connection
Dim rs As Recordset
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB;Persist
Security Info=False"
cn.Open
rs.ActiveConnection = cn
rs.Open "Select * from Products"
Do Until rs.EOF
    List1.AddItem rs(0)
    rs.MoveNext
Loop
Set rs=nothing
set cn=nothing


Quote:

> I have a problem. (Surprise, surprise !)

> I have a code like this :

> Dim cmd As ADODB.Command
> Dim conn As ADODB.Connection

> Set cmd = new ADODB.Command
> cmd.CommandText = "GetPublisherDetail"
> cmd.CommandType = adCmdStoredProc

> cmd.Parameters.Append cmd.CreateParameter("PublisherId", adInteger,

adParamInput, , varPublisherId)
Quote:

> conn.Open strconnect
> Set cmd.ActiveConnection = conn
> ..

> Of course it's not working. I traced the code and it fails on the
> "Set cmd.ActiveConnection = conn".

> The conn.Errors collection contains those two errors:
>         [Microsoft][ODBC SQL Server Driver][SQL Server]Changed database
context to 'xxx'.
>         [Microsoft][ODBC SQL Server Driver][SQL Server]Changed language

setting to us_english.
Quote:

> And the cmd.ActiveConnection is not set.

> Does anyone have any idea what could be wrong?

> In case it matters.
> The code is in a COM object.

> Erm, actualy in two. The first one creates and fills the cmd, then creates

the other one and passes the cmd.
Quote:
> The second one creates conn and sets the activeconnection property of cmd

and opens a recordset.
Quote:
> I tried to pass the cmd both byRef and byVal :

> Public Function GetDisconnectedRecordSetFromCommand _
>     ( _
>     ByRef cmd As ADODB.Command, _
>     ByRef rst As ADODB.Recordset _
>     ) As Variant

> Thanks for any insight, Jenda
> P.S.: CC will be appreciated.



Wed, 05 Nov 2003 12:01:34 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Problems setting ActiveConnection in ADODB.Command

2. Problems setting ActiveConnection in ADODB.Command

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. ADODB.Recordset Conn. to Oracle vs MSSQL

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

8. Command.activeconnection vs connection.open

9. Command.ActiveConnection returning strange error

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

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

12. Conn.Execute vs. Command Object w/Oracle

 

 
Powered by phpBB® Forum Software