ADO Error 3001, when setting the connection

Hi,

I have a dll with two properties, a Set and Get:

Property Get objConn() As ADODB.Connection
    Set objConn = m_objConn
End Property

Property Set objConn(objNewValue As ADODB.Connection)
    Set m_objConn = objNewValue
End Property

I have a test exe, which creates this connection object (successfully) and then sets the property in the dll to this object, which also works.


But when I try and set the connection:


Dim objCommand As ADODB.Command
Set objCommand = New ADODB.Command
       
Set objCommand.ActiveConnection = m_objConn ' error here

I get an error (even though the m_objConn appears to contain the right connection string?):

"Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another."

Has anyone come across this problem before?

Thanks in advance.
mdelmarAsked:
Who is Participating?
 
moduloCommented:
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0
 
RainUKCommented:
In MSDN there is a reference to this error happening with ADO Recordsets.

FIX: Setting Rst.ActiveConnection to a Recordset Causes GPF

Article: Q193093

But they say this problem has been fixed with MDAC v2.1 SP2. So you could try donloading latest and greatest MDAC to see if it resolves your problem.

Well try the connection with a recordset object, if you get the same error using the Rs object then get the latest MDAC.




0
 
Hawkeye67Commented:
I attempted to duplicate your problem:  Here is what I discovered might be the problem.

In your dll your code appears okay, as I duplicated it and it connected to my SQL Server 7.0.  In your Test.exe make sure to reference your dll and declare an obj of the dll.cls that contains your connection information, set and get, etc.  It appears as though you are trying to access the private module level variable in the class that you are using to pass the connection object through your set and get in the dll.  Try the following as an experiment and see if this doesn't work:

The dll's class code:

Option Explicit

Private m_objConn As ADODB.Connection

Public Property Get objConn() As ADODB.Connection
    Set objConn = m_objConn
End Property
Public Property Set objConn(cn As ADODB.Connection)
    Set objConn = cn
End Property

Private Sub Class_Initialize()
    Set m_objConn = New ADODB.Connection

    ' substitute your own connection string here
    m_objConn.ConnectionString = "Provider=SQLOLEDB.1;Data Source=HAWKEYE;Initial Catalog=Northwind;User ID=sa;Password=;"
   
    m_objConn.Open
End Sub


In the test project which is added to the dll project, in the form put the following code:

Option Explicit

Private cmd As ADODB.Command
Private obj As Project1.clsdataaccess

Private Sub Form_Load()
    Set cmd = New ADODB.Command
    Set obj = New Project1.clsdataaccess

    If obj.objconn.state then
          msgbox "Connection open"
         'set the command object connection to the public
         ' connection variable in the dll class, not the
         ' module level private variable which is what
         ' you appear to be doing.
          Set cmd.ActiveConnection = obj.objconn
    End If
End Sub


Following your information, I was unable to get the same error.  However, when I used the code Set objCommand.ActiveConnection = m_objConn I got "variable not defined" as an error.

I hope this helps.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Hawkeye67Commented:
Sorry, forgot to add that you also need to make a reference to the appropriate ADO object library in your Test.exe along with the reference to your dll.

Good luck.
0
 
mdelmarAuthor Commented:
Hi again,

It turned out that I needed to open the connection object in the dll, after I set the connection property (I presumed that as I was passing the dll an already opened object from the exe, that I wouldn't need to do this??)

Thanks for your help - that was a tricky one!
0
 
DanRollinsCommented:
Hi mdelmar,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

mdelmar, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.