Link to home
Start Free TrialLog in
Avatar of Anderson_Enterprises
Anderson_Enterprises

asked on

ODBC, VB, [Data Control | ADO Data Control] -- I need to connect and release when requested.

My data control hogs up access to the FoxPro database (through ODBC) and prevents my program from Zapping the records.

I am making an ActiveX Calendar Control.

Here is the order of operations

User clicks the Tab in FoxPro.
FoxPro USE EXCLUSIVE's the Calendar table, Clears it. Loads it with real data. Then tells the calendar to REFRESH based on the new data.

Everything works, except i get an error telling me that fox cant use the database exclusive because the control has a finger in it.

How can i (programically) create the connection?

I'm using a Data Control (vb6) and have been told to switch to ADO data control.

I DO NOT WANT TO SET THE CONNECTION THROUGH THE PROPERTY WINDOW BECAUSE I NEED TO START AND STOP IT VIA CODE.

Cheers, It's important : ) So answer quickly
Avatar of PePi
PePi

I am assuming you are using VB6.

Dim oConn as New ADODB.Connection

'the code below opens a connection to your foxpro database
'
oConn.Open "Provider=vfpoledb;" & _
           "Data Source=C:\vfp8\Samples\Data\myVFPDB.dbc;" & _
           "Mode=ReadWrite|Share Deny None;" & _
           "Collating Sequence=MACHINE;" & _
           "Password=''"

The Visual FoxPro OLE DB Provider is not installed by MDAC 2.x.  You must install Visual FoxPro or download the OLE DB Provider

You also have to add Microsoft ActiveX Data Objects 2.6 Library to your References

Avatar of Anderson_Enterprises

ASKER

How do i get to the fields?

Data1.RecordSet.Fields("Age")

was the old way.
I prefer to use an ODBC connection. i already have one made that worked previously..

How do i start an ODBC connection via code?
ASKER CERTIFIED SOLUTION
Avatar of PePi
PePi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you mean your ODBC DSN has already been setup? if so, all you have to do is:

assuming you called your DSN connection as dsnFoxPro

Dim oConn as New ADODB.Connection

oConn.Open dsnFoxPro
So that everyone (for future reference) knows how i got it to work:

REFERENCE: Microsoft ActiveX Data Objects 2.6

Dim rsConn as New ADODB.Connection
Dim rsRec as New ADODB.Recordset

rsConn.Open "Terms_Inventory" ' <--- That's my ODBC connection in the control panel
rsRec.Open "SELECT * FROM Inventory", rsConn, adOpenDynamic, adLockPessimistic

While Not rsRec.EOF
    MsgBox(rsRec.Fields("Date"))
    rsRec.MoveNext
Wend

rsConn.Close
rsRec.Close
Set rsConn = Nothing
Set rsRec = Nothing