Solved

ADO Error 3001, when setting the connection

Posted on 2001-08-31
6
486 Views
Last Modified: 2013-11-23
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.
0
Comment
Question by:mdelmar
6 Comments
 
LVL 5

Expert Comment

by:RainUK
ID: 6444355
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
 

Expert Comment

by:Hawkeye67
ID: 6444367
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
 

Expert Comment

by:Hawkeye67
ID: 6444374
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:mdelmar
ID: 6450197
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
 
LVL 49

Expert Comment

by:DanRollins
ID: 7205332
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
 

Accepted Solution

by:
modulo earned 0 total points
ID: 7758373
Finalized as proposed

modulo

Community Support Moderator
Experts Exchange
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now