Results 1 to 8 of 8

Thread: Can't have 2 connection objects?

  1. #1

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945

    Can't have 2 connection objects?

    I have this in my declarations:
    VB Code:
    1. Public CN As ADODB.Connection
    2. Public RS As ADODB.Recordset
    I've used this code before, but only with 1 connection. I open the connection like this:
    VB Code:
    1. Set CN = New ADODB.Connection
    2. CN.Provider = "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=labuser;Initial Catalog=Nonconf;Data Source=myserver"
    3. CN.Open
    My problem is, I have to open a connection to a different database while this connection is open. So I copied the declarations of the CN and RS objects and added a "2" after each. Now it won't even open the first connection claiming "Provider not found, It may not be installed". If I remove the declaration of the second connection object, it works fine. I cannot reuse the same connection on 2 different databases can I?

    What am I doing wrong? Why won't it allow me to have 2 connection objects?

    Using: VB6, SP5 w/ ADO and SQL Server 2K
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  2. #2

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Update... now the connection object won't work at all
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    ober0330,

    I never had this problem...

    I misunderstood something, so I'll ask you to make it crystal clear and try to help you, if I can...

    You have 2 connections, right ?

    When it's only one connection there's no problem, but when you create the second one, it crashs....

    My questions are:

    1) Both connetions are pointing for the same DB ? (I think it doesn't but...)

    2) No connection happens ? (nor 1st or 2nd) ?


    edit:

    Can you, please, post your code ?

    JL
    Last edited by Jlarini; Aug 20th, 2004 at 09:03 AM.
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  4. #4

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Ok, it doesn't seem to be a problem with the 2 connections anymore. I've deleted the code for the second connection and I still get the error "Provider cannot be found. It may not be properly installed."

    I don't understand what could have happened. It worked just a few minutes ago (before I started messing around with the 2 connections. And the 2 connections are to 2 different databases, not one.

    The code involved is posted above. That's all there is to it. When it gets to the "CN.Open", it gives the above error.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    I've now opened up a new project, tried creating a connection, and I STILL get this error. Have I corrupted something????
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  6. #6
    Hyperactive Member Jlarini's Avatar
    Join Date
    Jan 2002
    Location
    São Paulo, Brazil
    Posts
    263
    As I see no reason for that problem...
    I'll give you a silly (maybe) suggestion:

    Did you restarted your computer after the problem ?!?!?

    It's the Bill Gates' solution!!!

    I think it's a bet... (maybe not the good one...)

    JL
    nothing is impossible, it's sometimes very hard to do!

    If your thread is solved... Please edit it and add [Resolved] or [Solved] on it!

    If you like Marine aquarium, feel free to PM me.

    Sorry my bad English

    God bless Parksie!

  7. #7

    Thread Starter
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    I've restarted, installed the MDAC 2.8 components over again, downloaded the MDAC 2.8 SDK....

    I think I've hosed my system somehow.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Can't have 2 connection objects?

    Originally posted by ober0330
    I have this in my declarations:
    VB Code:
    1. Public CN As ADODB.Connection
    2. Public RS As ADODB.Recordset
    I've used this code before, but only with 1 connection. I open the connection like this:
    VB Code:
    1. Set CN = New ADODB.Connection
    2. CN.[b]Provider [/b]= "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=labuser;Initial Catalog=Nonconf;Data Source=myserver"
    3. CN.Open
    My problem is, I have to open a connection to a different database while this connection is open. So I copied the declarations of the CN and RS objects and added a "2" after each. Now it won't even open the first connection claiming "Provider not found, It may not be installed". If I remove the declaration of the second connection object, it works fine. I cannot reuse the same connection on 2 different databases can I?

    What am I doing wrong? Why won't it allow me to have 2 connection objects?

    Using: VB6, SP5 w/ ADO and SQL Server 2K
    You have got it all cocked up. Try setting that as the ConnectionString intead of the Provider.

    TG
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width