Solved

Connecting to FoxPro database with ADO

Posted on 2006-12-01
5
379 Views
Last Modified: 2013-12-25
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

0
Comment
Question by:tcalbaz
  • 2
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
leonstryker earned 500 total points
ID: 18069265
Try this:

Private Function ConnectDBF() As Boolean
    Dim oCn As New ADODB.Connection
    Dim oRn As New ADODB.Recordset
    Dim strSQL As String

    oCn.Open "Driver={Microsoft Visual FoxPro Driver};" & _
           "SourceType=DBF;" & _
           "SourceDB=d:\pos;" & _
           "Exclusive=No"

    oRn.CursorLocation = adUseClient

    strSQL = "Select  * from MyData.dbf"
    oRn.Open strSQL, oCn, adReadOnly, adLockOptimistic

    Msgbox oRn.RecordCount

    oRn.Close
    Set oRn = Nothing
    oCn.Close
    Set oCn = Nothing
End Function
0
 
LVL 1

Author Comment

by:tcalbaz
ID: 18069381
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
0
 
LVL 29

Expert Comment

by:leonstryker
ID: 18069415
I think the problem is with your connection string.  Take a look here:  

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

Leon
0
 
LVL 1

Author Comment

by:tcalbaz
ID: 18070270
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
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…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

920 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

17 Experts available now in Live!

Get 1:1 Help Now