Results 1 to 10 of 10

Thread: [RESOLVED] ADO to read dbf not working

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Resolved [RESOLVED] ADO to read dbf not working

    According to all posts I have seen, this shold work, but of course it doesn't, does anyone see what is wrong....

    DBF is on C:\temp\test.dbf


    Dim DB As New ADODB.Connection
    Dim RS As New ADODB.Recordset

    dim sFilePath as string = "C:\temp"

    DB.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & sFilePath & ";Extended Properties=DBase IV")


    Dim sQuery As String
    sQuery = "Select * From test.dbf"

    RS.Open(sQuery, DB, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic, )

    It blows up on the RS.Open line, saying file not found. I know it is there.

    Thanks so much.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: ADO to read dbf not working

    Are you using .NET or VB6? You posted in the .NET forum, but posted ADO Classic code.

    Also you don't need the .dbf in the table name... it's implied... jsut SELECT * FROM test will be sufficient.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Re: ADO to read dbf not working

    thanks for your hasty reply. I am in vb.net, VS2005, from the examples I have seen, the code didn't matter.
    I did try the .open without the .dbf and still get the message

    Microsoft jet engine coud not find the object 'test', make sure it exists or spelled properly.

    Do you have a sample of it actually working? otherwise I must find another method to read the dbf file.

    THanks

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: ADO to read dbf not working

    Yes I have code to open DBF files... but it's ADO.NET code...(and it is at home) but since you are using VS2005, then that will be fine - shouldn't be using ADO.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Re: ADO to read dbf not working

    thanks, I would really appreciate it. I have been meaning to use ADO.NET anyway, but holding off on it.

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: ADO to read dbf not working

    Here's how I read in dbf files using ADO.NET:

    Code:
        Friend Const _DBF As String = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=dBASE IV;User ID=Admin;Password=;Data Source="
    
            Dim DbfConn As OleDb.OleDbConnection = New OleDb.OleDbConnection(_DBF & Configuration.ArchiveRoot & "\Processing")
            DbfConn.Open()
            Dim DbfCommand As OleDb.OleDbCommand = New OleDb.OleDbCommand("SELECT * FROM dbf_table", DbfConn)
            Dim myDataAdapter As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(DbfCommand)
            Dim myDataTable As DataTable = New DataTable
            myDataAdapter.Fill(myDataTable)
            DbfConn.Close()
    I used _DBF as a constant for the connectionstring, sans the path to the dbf files. I build up that part when I create the connection. In this case Configuration.ArchiveRoot was an application setting that pointed to the folder where I was processing the files from (they were coming to me in zip format, which I then unzipped to the Processing folder, that's where that comes from). "dbf_table" is then the name of the dbf file, in this case dbf_table.dbf ...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Re: ADO to read dbf not working

    Thanks so much for the snippet, but it is still giving me the same error as before on this line
    myDataAdapter.Fill(myDataTable)

    Microsoft Database engine could not find object 'Lookup_table'

    So it is not the method that is the problem I even tried to open another dbf, just to make sure and same thing. Any other ideas????
    Is there another way to read DBF's that may not be as elegant, I just need to read this file.

    THanks,

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Thumbs up Re: ADO to read dbf not working

    I got it to work!!!!
    I copied the file and renamed it, I am not sure what this did, maybe there was something corrupt or whatever, I can't explain, but it now reads all the records.

    THanks so much.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Apr 2003
    Posts
    193

    Re: [RESOLVED] ADO to read dbf not working

    FYI for anyone else having similar problem. It was not that the file was corrupt, but the name was too long!! Apparently, there is a limit, not sure if it is 7 or 8, but I cut it to 7 and it works fine.
    Crazy waste of energy.
    Cheers.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] ADO to read dbf not working

    wow... that's news to me... Thanks for sharing that.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width