Opening a dbf file with .NET code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • genojoe

    #1

    Opening a dbf file with .NET code

    I have a simple dbf file with the name of OTHWAGE.dbf. I can open it in
    Visual Studio Server Explorer and see its fields and records by creating a
    Data Connection. When I copy the connection string and combine it with code
    from VS Help, I end up with the following:

    Dim sConnection As String = "Provider=MSDAS QL.1;
    Persist Security Info=False;
    Data Source=dBASE Files;
    Extended Properties=""DS N=dBASE Files;DBQ=C:\Te mp;
    DefaultDir=c:\P rogram Files\Microsoft Visual Studio .NET 2003\Common7\ID E;
    DriverId=533;Ma xBufferSize=204 8;
    PageTimeout=5
    ;"";
    Initial Catalog=C:\Temp "

    Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
    Dim myConnection As New System.Data.Odb c.OdbcConnectio n(sConnection)
    Dim myCommand As New System.Data.Odb c.OdbcCommand(m ySelectQuery,
    myConnection)
    myConnection.Op en()
    Dim myReader As
    System.Data.Odb c.OdbcDataReade r = myCommand.Execu teReader()
    While myReader.Read()
    Console.WriteLi ne(myReader.Get String(1))
    End While

    For readability purposes, I added carriage returns to the connection string.
    When I execute this code, I get a system error at the myConnection.Op en()
    line. What I am I doing wrong with this simple code?
  • Cindy Winegarden

    #2
    Re: Opening a dbf file with .NET code

    Hi Joe,

    First off, try the FoxPro and Visual FoxPro OLE DB data provider, available
    from http://msdn.microsoft.com/vfoxpro/downloads/updates . For your
    connection string use:

    "Provider=VFPOL EDB.1;Data Source = C:\Temp;"

    That's all you need for free tables. If you still have problems, post back.

    --
    Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
    cindy_winegarde n@msn.com www.cindywinegarden.com
    Blog: http://spaces.msn.com/members/cindywinegarden


    "genojoe" <genojoe@discus sions.microsoft .com> wrote in message
    news:76E85ABF-126C-4D3C-8FA3-A99819194003@mi crosoft.com...[color=blue]
    >I have a simple dbf file with the name of OTHWAGE.dbf. I can open it in
    > Visual Studio Server Explorer and see its fields and records by creating a
    > Data Connection. When I copy the connection string and combine it with
    > code
    > from VS Help, I end up with the following:
    >
    > Dim sConnection As String = "Provider=MSDAS QL.1;
    > Persist Security Info=False;
    > Data Source=dBASE Files;
    > Extended Properties=""DS N=dBASE Files;DBQ=C:\Te mp;
    > DefaultDir=c:\P rogram Files\Microsoft Visual Studio .NET 2003\Common7\ID E;
    > DriverId=533;Ma xBufferSize=204 8;
    > PageTimeout=5
    > ;"";
    > Initial Catalog=C:\Temp "
    >
    > Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
    > Dim myConnection As New
    > System.Data.Odb c.OdbcConnectio n(sConnection)
    > Dim myCommand As New System.Data.Odb c.OdbcCommand(m ySelectQuery,
    > myConnection)
    > myConnection.Op en()
    > Dim myReader As
    > System.Data.Odb c.OdbcDataReade r = myCommand.Execu teReader()
    > While myReader.Read()
    > Console.WriteLi ne(myReader.Get String(1))
    > End While
    >
    > For readability purposes, I added carriage returns to the connection
    > string.
    > When I execute this code, I get a system error at the myConnection.Op en()
    > line. What I am I doing wrong with this simple code?[/color]


    Comment

    • genojoe

      #3
      Re: Opening a dbf file with .NET code

      I agree it should work. This time I even began a new project (on same
      computer). One form, one button. FoxPro provider worked great in the Server
      Explorer.

      I crash at last line of code shown below:

      Dim sConnection As String = "Provider=VFPOL EDB.1;Data Source = C:\Temp;"
      Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
      Dim myConnection As New System.Data.Odb c.OdbcConnectio n(sConnection)
      Dim myCommand As New System.Data.Odb c.OdbcCommand(m ySelectQuery, myConnection)

      myConnection.Op en()

      Error message is:
      An unhandled exception of type 'System.Data.Od bc.OdbcExceptio n' occurred in
      system.data.dll

      Additional information: System error.

      Thank you for the response. Any more thoughts?
      =============== ===

      "Cindy Winegarden" wrote:
      [color=blue]
      > Hi Joe,
      >
      > First off, try the FoxPro and Visual FoxPro OLE DB data provider, available
      > from http://msdn.microsoft.com/vfoxpro/downloads/updates . For your
      > connection string use:
      >
      > "Provider=VFPOL EDB.1;Data Source = C:\Temp;"
      >
      > That's all you need for free tables. If you still have problems, post back.
      >
      > --
      > Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
      > cindy_winegarde n@msn.com www.cindywinegarden.com
      > Blog: http://spaces.msn.com/members/cindywinegarden
      >[/color]

      Comment

      • genojoe

        #4
        Re: Opening a dbf file with .NET code

        I got the following to work:

        Dim myConnection As New
        System.Data.Ole Db.OleDbConnect ion("Provider=M icrosoft.Jet.OL EDB.4.0;Data
        Source=C:\TEMP; Extended Properties=dBas e III")
        Dim myCommand As New System.Data.Ole Db.OleDbCommand ("SELECT
        OTHWAGE.* FROM OTHWAGE", myConnection)
        myConnection.Op en()
        Dim myReader As System.Data.Ole Db.OleDbDataRea der =
        myCommand.Execu teReader()
        While myReader.Read()
        Debug.WriteLine (CStr(myReader. GetValue(0)))
        End While


        "Cindy Winegarden" wrote:
        [color=blue]
        > Hi Joe,
        >
        > First off, try the FoxPro and Visual FoxPro OLE DB data provider, available[/color]

        Comment

        • Cindy Winegarden

          #5
          Re: Opening a dbf file with .NET code

          Hi Joe,

          I'm glad you found a work-around.

          --
          Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
          cindy_winegarde n@msn.com www.cindywinegarden.com
          Blog: http://spaces.msn.com/members/cindywinegarden


          "genojoe" <genojoe@discus sions.microsoft .com> wrote in message
          news:EDDDDB6D-D348-403F-B9C0-B8135C8CD504@mi crosoft.com...[color=blue]
          >I got the following to work:
          >
          > Dim myConnection As New
          > System.Data.Ole Db.OleDbConnect ion("Provider=M icrosoft.Jet.OL EDB.4.0;Data
          > Source=C:\TEMP; Extended Properties=dBas e III")
          > Dim myCommand As New System.Data.Ole Db.OleDbCommand ("SELECT
          > OTHWAGE.* FROM OTHWAGE", myConnection)
          > myConnection.Op en()
          > Dim myReader As System.Data.Ole Db.OleDbDataRea der =
          > myCommand.Execu teReader()
          > While myReader.Read()
          > Debug.WriteLine (CStr(myReader. GetValue(0)))
          > End While
          >
          >
          > "Cindy Winegarden" wrote:
          >[color=green]
          >> Hi Joe,
          >>
          >> First off, try the FoxPro and Visual FoxPro OLE DB data provider,
          >> available[/color]
          >[/color]


          Comment

          Working...