Solved

VB6: Cannot change connection provider for Data Environment connection

Posted on 2003-10-23
7
2,083 Views
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
        DeApcoErs.conArchive.Close
    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...".

Regards.
0
Comment
Question by:maucher
  • 3
  • 3
7 Comments
 
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.

Anthony
0
 

Author Comment

by:maucher
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.

maucher
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 9610870
maucher

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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:maucher
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?

maucher
0
 
LVL 29

Accepted Solution

by:
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.

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/VB_Databases/Q_20766815.html
0
 

Author Comment

by:maucher
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.Open
    DeApcoErs.conArchive.Close
    DeApcoErs.conArchive.Provider = "Microsoft OLE DB Provider for SQL Server;"

Thanks,
maucher
0
 
LVL 29

Expert Comment

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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now