VB6: Cannot change connection provider for Data Environment connection

Posted on 2003-10-23
Last Modified: 2013-12-25
VB6 program has a Data Environment with an ADO connection "conArchive".  In VB6 development environment, the provider is set to "Microsoft Jet 4.0 OLE DB Provider" along with an .mdb Data Source file.

When the program starts, it may need to change to a SQL database provider with this code:

    If DeApcoErs.conArchive.State <> adStateClosed Then
    End If
    DeApcoErs.conArchive.Provider = "Microsoft OLE DB Provider for SQL Server;"

which causes this error: "Supplied provider is different from the one already in use."

Trying to set the connection string to a SQL provider, source, etc. also causes and error: "multiple step error...".

Question by:maucher
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
  • 3
  • 3
LVL 75

Assisted Solution

by:Anthony Perkins
Anthony Perkins earned 50 total points
ID: 9610679
Try setting the Data Environment to nothing and re-creating prior to reopening with a new provider.


Author Comment

ID: 9610830
I tried each of these in DataEnvironment_Initialize()

     Set DeApcoErs.conArchive = Nothing      ' returns "Invalid use of property"
     Set DeApcoErs.conArchive = New ADODB.Connection

     Set DeApcoErs = Nothing
     Set DeApcoErs = New DataEnvironment      
     ' returns "Class does not support automation or does not support expected interface"

DeApcoErs  has several connections and many commands in it.  I would like to do away with it, but that's a big change for later.

LVL 29

Expert Comment

ID: 9610870

In order to do switch the DE you will have to destroy all of the Command objects, set the new DE and recreate the Commands.
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

ID: 9615212
The Data Environment is statically defined in the project / Designers.  It contains 8 connections and the connections contain about 100 commands.  

Can I just work with the connection DeApcoErs.conArchive?  When I try to set the connection to nothing, "Invalid use of property" error occurs.

Still get "Supplied provider is different from the one already in use." for this statement:

    Private Sub DataEnvironment_Initialize()
        DeApcoErs.conArchive.Provider = "Microsoft OLE DB Provider for SQL Server;"
    end sub

Is there a way to change the provider that is in use without changing the whole data environment?

LVL 29

Accepted Solution

leonstryker earned 75 total points
ID: 9615293
This is one of the problems witht he Data Enviroment object.  I recently posted a question about DE which you may want to take a look at.

Author Comment

ID: 9617313
I agree that the Data Environment has some limitations as the posted question and linked article point out.  

My solution is this work-around which sets the connection string to a different valid Jet database, opens and closes, and then changes the provider to the desired SQL Server database.  It works, but I'm not sure why:

    DeApcoErs.conArchive.ConnectionString = DeApcoErs.ConCases.ConnectionString
    DeApcoErs.conArchive.Provider = "Microsoft OLE DB Provider for SQL Server;"

LVL 29

Expert Comment

ID: 9617339
I think it may work because the Commands are disengaged while opening a different Jet database.

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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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 Month5 days, 3 hours left to enroll

636 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