Read dBase in asp.net

Discussion in 'ASP .Net' started by David C, Oct 2, 2009.

  1. David C

    David C Guest

    I have a web application that needs to read several dBase files created by a
    user application. I can read them and display display them in a GridView
    just fine using the code example below.

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.Load
    Dim sConnectionString As String
    Dim strSQL As String = "SELECT * FROM " & "1KGI0CYV"

    sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
    "Data Source=\\ltserver\Apps\Pathways\Data\extcomm\emsout\;Extended
    Properties=dBase IV"
    Dim objConn As New
    System.Data.OleDb.OleDbConnection(sConnectionString)
    objConn.Open()

    Dim da As New System.Data.OleDb.OleDbDataAdapter(strSQL, objConn)

    Dim ds As New DataSet("1KGI0CYV")

    da.Fill(ds, "1KGI0CYV")

    Dim dt As DataTable
    dt = ds.Tables("1KGI0CYV")
    gvEnvFiles.DataSource = dt

    gvEnvFiles.DataBind()

    objConn.Close()

    End Sub

    The problem is that each dBase file has to be renamed with a .dbf extension
    for the above to work.
    The example file above is named 1KGI0CYV.env and I would like to open it
    without renaming it, if possible.
    When I try to add the file name to the Data Source= parameter it fails with
    the error "... is not a valid path."

    Thanks.
    David
     
    David C, Oct 2, 2009
    #1
    1. Advertising

  2. David C

    David C Guest

    "Mark Rae [MVP]" <> wrote in message
    news:...
    > "David C" <> wrote in message
    > news:...
    >
    >> The example file above is named 1KGI0CYV.env and I would like to open it
    >> without renaming it, if possible.

    >
    > It's been a while but, AFAICR, this is not possible and what you are
    > seeing is expected behaviour...
    >
    > With dBase, the folder in which the dbf files resides is considered to be
    > the database and the individual dbf files are considered to be the tables.
    >
    > So, when you point at a dbf file, the OleDb driver strips of ".dbf" from
    > the filename and then considers that whatever's left is the database. In
    > your case, this won't work i.e. Database =
    > "C:\1KGI0CYV.env".Replace(".dbf", "") means that the OleDb provider is now
    > looking for a folder called "C:\1KGI0CYV.env", which doesn't exist...
    >
    >
    >> When I try to add the file name to the Data Source= parameter it fails
    >> with the error "... is not a valid path."

    >
    > Indeed so.
    >
    >
    > --
    > Mark Rae
    > ASP.NET MVP
    > http://www.markrae.net


    Thank you. I thought this was the case since I had no luck with everything I
    tried.

    Will I run into problems if I rename each file just before opening it, then
    naming it back to the original name? I sometimes have an issue with the web
    server "catching up" with files when moved, deleted or renamed when I do
    something in the same page (file caching issue???) and the same directory.
    This user application creates about 15 dbf files with different extensions,
    but the same file name. For example 1KGI0CYV.env, 1KGI0CYV.lin,
    1KGI0CYV.ttl, etc.

    Thanks.
    David
     
    David C, Oct 2, 2009
    #2
    1. Advertising

  3. "David C" <> wrote in
    news::

    > The problem is that each dBase file has to be renamed with a .dbf
    > extension for the above to work.
    > The example file above is named 1KGI0CYV.env and I would like to open
    > it without renaming it, if possible.
    > When I try to add the file name to the Data Source= parameter it fails
    > with the error "... is not a valid path."


    It appears the Jet Provider for dBase does not allow anything other than
    the default naming, so you need to figure out if there is another provider
    that allow other naming conventions. Perhaps this will work for you?
    http://www.vistasoftware.com/

    As far as the "default" or "normal" method for ISAM databases, it is a
    directory with multiple files. Apparently, the jet Provider has the .dbf
    hard coded. I am not sure if there is any way around this.

    Peace and Grace,

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
     
    Gregory A. Beamer, Oct 2, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aurelio
    Replies:
    0
    Views:
    2,740
    Aurelio
    Jan 2, 2006
  2. nicholas
    Replies:
    2
    Views:
    403
    nicholas
    Oct 7, 2004
  3. loreille
    Replies:
    1
    Views:
    4,489
    Ben Strackany
    Oct 28, 2004
  4. loreille
    Replies:
    0
    Views:
    461
    loreille
    Oct 28, 2004
  5. Vishal

    Import to dbase via excel

    Vishal, Nov 29, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    488
    Jeff Dillon
    Nov 30, 2004
Loading...

Share This Page