Link to home
Start Free TrialLog in
Avatar of tcalbaz
tcalbazFlag for United States of America

asked on

Connecting to FoxPro database with ADO

Vernerable Guru's,
I'm a little rusty using VB6/ADO and FoxPro Tables
I seem to be doing something wrong connecting to a FoxPro Database Table that I need to process.  The routine I have below appears to connect but as soon as I wish to do anything significant such as moving to end of the table or getting a record count it flakes out.  Can someone enlighten me whats going on to correct it?

Thank you!

Ted

Code ------------------------------------------------------------

Private Function ConnectDBF() As Boolean
    On Error GoTo Err_Handler
    Dim oCn As New ADODB.Connection
    Dim oRn As New ADODB.Recordset
    Dim oCd As New ADODB.Command
    Dim bColor As Long
    Dim sConn As String
    Const CONNECTION_STRING = "DSN=POS_DBF;UID=;PWD="
   
    Screen.MousePointer = 11
    oCn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
           "SourceType=DBF;" & _
           "SourceDB=d:\pos;" & _
           "Exclusive=No"
   
    Set oCd.ActiveConnection = oCn
    oCd.CommandText = "Select  * from MyData.dbf"
    oRn.CursorLocation = adUseClient
    oRn.Open oCd, , adOpenDynamic, adLockReadOnly
    cmdConnect.Font.Bold = True
    bColor = cmdConnect.BackColor
    cmdConnect.BackColor = vbRed
    Screen.MousePointer = 0
    MsgBox "Connected to DBF." , vbInformation
    Msgbox oRn.RecordCount    '<<<<<<<<<<< "E_FAIL" ERROR MESSAGE OCCURS HERE!
   

QUit_Handler:
    Set oRn = Nothing
    Set oCd = Nothing
    Set oCn = Nothing
    cmdConnect.BackColor = bColor
    cmdConnect.Font.Bold = False
    Screen.MousePointer = 0
    Exit Function
   
Err_Handler:
    cmdConnect.BackColor = bColor
    Screen.MousePointer = 0
    cmdConnect.Font.Bold = False
    MsgBox Err.Description, vbInformation
    Resume QUit_Handler
    Resume
End Function

ASKER CERTIFIED SOLUTION
Avatar of leonstryker
leonstryker
Flag of United States of America image

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
Avatar of tcalbaz

ASKER

leonstryker,

It appears that I got a similar result.  
When the code got to recordcount I got this Error:

"Data provider or other service returned an E_FAIL status"

I'm not sure why this is happening.  I'll try to find out a little more with google.

Thank you

Ted
I think the problem is with your connection string.  Take a look here:  

http://www.carlprothman.net/Default.aspx?tabid=87#OLEDBProviderForVisualFoxPro

Leon
Avatar of tcalbaz

ASKER

Leonstryker
I think your code is correct. I do think I have an issue with my drivers.
I'll work with this.

Thank you

Ted