Read dBase in asp.net

D

David C

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
 
D

David C

Mark Rae said:
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...



Indeed so.

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
 
G

Gregory A. Beamer

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,743
Messages
2,569,477
Members
44,898
Latest member
BlairH7607

Latest Threads

Top