Asp.net connectionissues to DBF database

Paulconsulting
Paulconsulting used Ask the Experts™
on
I am having some problems connecting from an asp.net application to a foxpro database named Customers.dbf.

With the code below, it looks like I am connecting but it can't find the table. I don't know what I am missing still.

Error:
Exception Details: System.Data.OleDb.OleDbException: The Microsoft Jet database engine could not find the object 'customers'.  Make sure the object exists and that you spell its name and the path name correctly.
Dim strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Websites\AppName\App_Data\;Extended Properties=dBASE IV;User ID=Admin;Password=;"
 
Dim objConn As New OleDbConnection
Dim objCmd As OleDbCommand
Dim ObjDR As OleDbDataReader
 
objConn.ConnectionString = strConnectionString
objCmd = New OleDbCommand("Select * from customers", objConn)
objCmd.CommandType = CommandType.Text
 
objConn.Open()
ObjDR = objCmd.ExecuteReader()
If ObjDR.Read() Then
            Response.Write("<Br>JobName: " & ObjDR("JobName"))
End If
ObjDR.Close()

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Seven priceFull Stack

Commented:
While ObjDR.Read
If ObjDR.Read() Then
            Response.Write("<Br>JobName: " & ObjDR("JobName"))
End If
end while

Author

Commented:
It is failing when the command reader is executing.  I changed my code to the above. ( I do realize that the code i had posted will only get one record, i was just trying to put up an example of what "code" was breaking")

It looks to me that it isn't finding the table  "Customers"
Line 32:         objConn.Open()
Line 33: 
Line 34:         ObjDR = objCmd.ExecuteReader() 'Falure on this line
Line 35:         While ObjDR.Read
Line 36:             If ObjDR.Read() Then

Open in new window

Randy Wilson.Net Developer

Commented:
Not real familiar with dBASE IV Jet driver, but don't you need a file name for the Data Source?

Data Source=D:\Websites\AppName\App_Data\ dbasdefilenamehere?
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Author

Commented:
From what I read on connecting to a foxpro databae, you don't add the filename at the end of the path, just the folder it resides in.
Randy Wilson.Net Developer

Commented:
So it is supposed to find the customers object from the Customers.dbf filename and use it?
Randy Wilson.Net Developer
Commented:
Cont'd:  If so, the error seems to be saying one of 3 things:  Either the pathname is wrong, there is no customers.dbf in the specified path, or the ASP.Net process does not have permissions to the path/databasefile...

Author

Commented:
Well:

1 - The path name is a correct direct path to the dbf  (maybe i have the path naming system wrong, such as i might need to do relative paths?)

2 - I see the Cusomers.dbf in the app folder

3 - For pure testing, i have given the entire folder "Full control" by the admin. I have also included impersonation in my web.config (<identity impersonate="true" userName="Administrator" password="12345"/>)

I wonder since it is in the app_data folder, asp.net won't give access to it. I am going to move the dbf to a new folder and test that.
FINALLY! I did a couple things wrong.

Okay, here is the solution:

1: I had to download the FoxPro Driver, and install the msi

2: not only does the *.DBF need to be there (obviously) but you have to have the *.FPT files as well in the samd folder

3: In the Select statement, you need to include the file path of the dbf you want to select from.

4: Also not sure of the permissions, but currently the folder has a crap load of permissions allowing basically full control to everything and now I just have to weed out the ones that are needed.
Dim strConnectionString As String = "Provider=VFPOLEDB.1;Data Source=D:\Websites\AppName\data\;Extended Properties=dBASE IV;User ID=Admin;Password=;"
   
 
 
Response.Write("ConnectionString: " & strConnectionString)
 
objConn.ConnectionString = strConnectionString
objCmd = New OleDbCommand("Select * from D:\Websites\QuincyJoist\data\CUSTOMERS.DBF", objConn)
objCmd.CommandType = CommandType.Text
 
        
objConn.Open()
   ObjDR = objCmd.ExecuteReader()
        While ObjDR.Read
            If ObjDR.Read() Then
                Response.Write("<Br>JobName: " & ObjDR("JobName"))
            End If
        End While
 
        ObjDR.Close()
        objCmd = Nothing
objConn.Close()

Open in new window

Seven priceFull Stack

Commented:
Ok lets try this from another angle if you are willing. When a cookie writes it writes the username how can i use this for example

Username@www.txt

If I can read the username from the text file
Seven priceFull Stack

Commented:
ok and I see you added my
while ObjDr.Read
Olaf DoschkeSoftware Developer

Commented:
ad 3: You don't need the full path, if the path you provide in the connection string is the path to the tables, the pure file name customers.dbf is sufficient.

Regarding permissons, well, whatever system account executes your ASP.net code will need permisson on DBFs of course. No more, no less.

Bye, Olaf.
Randy Wilson.Net Developer

Commented:
Thanks Paulconsulting, glad you got it to work.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial