Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ADO Error 3001, when setting the connection

Posted on 2001-08-31
6
Medium Priority
?
524 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
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
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…
Suggested Courses

886 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