Solved

ADO Error 3001, when setting the connection

Posted on 2001-08-31
6
509 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month10 days, 15 hours left to enroll

628 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