Solved

ADO Error 3001, when setting the connection

Posted on 2001-08-31
6
504 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
[X]
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
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dev express lookupcombo 3 64
pop out of webbrowser1 control vba6 5 52
How to make Sign in, using Clientdataset? 1 43
VBA Replace Function - What am I missing? 3 52
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

752 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