Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Passing an ADO connection to an ActiveX DLL

Posted on 2000-03-10
6
477 Views
Last Modified: 2013-11-23
I'm trying to pass an open ADO connection object to a method in an ActiveX DLL.

As soon as I try to open a recordset using this connection in the ActiveX DLL it gives me an error 3001.

I know the connection is good as im using it in the calling procedure and when I check the status of the connection in the ActiveX DLL everything looks fine.

I could just open another connection but I would rather use the open connection if possible.

I also tried passing an ADO recordset and this works fine!!!

Ive tried setting the connection as a property, as a parameter, creating a local connection and setting it to the passed connection all to no avail.

Anyone got any ideas?

Cheers
Kev
0
Comment
Question by:kevrob
6 Comments
 
LVL 6

Expert Comment

by:Tmess
ID: 2606759
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 200 total points
ID: 2606767
What does your code look like?

This is the code I have in a Standard EXE:

Private Sub Command1_Click()
Dim cnLocal As ADODB.Connection
Dim rstTemp As ADODB.Recordset
Dim x As New Class1

    Set cnLocal = New ADODB.Connection
    cnLocal.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\Microsoft Visual Studio\VB98\Nwind2000.mdb;Persist Security Info=False"
    Set x.gConnection = cnLocal
    Set rstTemp = x.OpenRecordset
    Do Until rstTemp.EOF
        MsgBox rstTemp!CompanyName
        rstTemp.MoveNext
    Loop
End Sub

Here is the code that I have in the DLL:
Option Explicit

Private mConnection As ADODB.Connection

Public Property Get gConnection() As Variant
    Set gConnection = mConnection
End Property

Public Property Set gConnection(ByVal vNewValue As ADODB.Connection)
    Set mConnection = vNewValue
End Property

Public Function OpenRecordset() As ADODB.Recordset
Dim rstX As New ADODB.Recordset

    rstX.CursorType = adOpenStatic
    Set rstX = mConnection.Execute("SELECT * FROM Shippers")
    Set OpenRecordset = rstX
End Function
0
 

Author Comment

by:kevrob
ID: 2607429
Your code does work but I need to know why mine dont as at work we usually use the open method of the recordset not use a connection or command .execute method. We only use these if its an sql update etc.

This is my code in the EXE

Private Sub Command1_Click()
Dim cnLocal As ADODB.Connection
Dim x As New clsTest

    Set cnLocal = New ADODB.Connection
    cnLocal.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Nwind.mdb;Persist Security Info=False"
    Call x.ProcessRecords(cnLocal)
   
    cnLocal.Close
    Set cnLocal = Nothing
End Sub


This is my code in the DLL

Public Sub ProcessRecords(ByVal adoConn As ADODB.Connection)
Dim rs As ADODB.Recordset

    Set rs = New ADODB.Recordset
    rs.Open "SELECT * FROM Shippers", adoConn, adOpenForwardOnly, adLockReadOnly
   
    With rs
        Do While Not .EOF
            Debug.Print !CompanyName
            .MoveNext
        Loop
        .Close
    End With
   
    Set rs = Nothing
End Sub

0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 70

Expert Comment

by:Éric Moreau
ID: 2607645
Hi kevrob,

Your code works perfectly on my PC!

Which version of ADO are you referencing? I doubt you use 2.0 (or less). Upgrade to at least 2.1 (from http://www.microsoft.com/data/).

Another thing you can try is to send the connection ByRef instead of ByVal like this:
Public Sub ProcessRecords(ByRef adoConn As ADODB.Connection)
0
 

Author Comment

by:kevrob
ID: 2608271
Ive tried both verions 2.0 & 2.1 of the ActiveX data libraries but both give me the same error message. I've also tried by ref and byval and still no good. Its got to be down to something on my machine.

Ive accepted your answer anyway and i'll try the same code on another machne, or as a drastic messure  rebuild my machine and see if that fixes the problem.

At worst I'll just use the execute method of the connection object passed

Cheers

Kevrob
0
 

Expert Comment

by:davelowndes
ID: 5704226
The comments here didn't answer the question which is why you cannot pass the reference to the connection object. Here's the answer from another PAQ:

From: afpcos
 Date: Tuesday, May 23 2000 - 10:06PM NZST  
You can not pass a connection out of the process in which it was created.

I am using connection pooling in my project.  I tried the same thing that you are talking about when I was first designed my project, about 9 months ago.  I was unsuccessfull in passing a connection between the exe and activex exe.  After calling Microsoft,  they advised that it is not possible to pass a connection out of process, such as from an exe to an active x exe or the other way around.

I am now managing the connection and all sql work in the active x exe passing back to the exe disconnected recordsets.  
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

856 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