472,101 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,101 software developers and data experts.

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=MSDASQL.1;
Persist Security Info=False;
Data Source=dBASE Files;
Extended Properties=""DSN=dBASE Files;DBQ=C:\Temp;
DefaultDir=c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE;
DriverId=533;MaxBufferSize=2048;
PageTimeout=5
;"";
Initial Catalog=C:\Temp"

Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery,
myConnection)
myConnection.Open()
Dim myReader As
System.Data.Odbc.OdbcDataReader = myCommand.ExecuteReader()
While myReader.Read()
Console.WriteLine(myReader.GetString(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.Open()
line. What I am I doing wrong with this simple code?
Nov 21 '05 #1
4 14242
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=VFPOLEDB.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
ci**************@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden
"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:76**********************************@microsof t.com...
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=MSDASQL.1;
Persist Security Info=False;
Data Source=dBASE Files;
Extended Properties=""DSN=dBASE Files;DBQ=C:\Temp;
DefaultDir=c:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE;
DriverId=533;MaxBufferSize=2048;
PageTimeout=5
;"";
Initial Catalog=C:\Temp"

Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New
System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery,
myConnection)
myConnection.Open()
Dim myReader As
System.Data.Odbc.OdbcDataReader = myCommand.ExecuteReader()
While myReader.Read()
Console.WriteLine(myReader.GetString(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.Open()
line. What I am I doing wrong with this simple code?

Nov 21 '05 #2
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=VFPOLEDB.1;Data Source = C:\Temp;"
Dim mySelectQuery As String = "SELECT OTHWAGE.* FROM OTHWAGE"
Dim myConnection As New System.Data.Odbc.OdbcConnection(sConnection)
Dim myCommand As New System.Data.Odbc.OdbcCommand(mySelectQuery, myConnection)

myConnection.Open()

Error message is:
An unhandled exception of type 'System.Data.Odbc.OdbcException' occurred in
system.data.dll

Additional information: System error.

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

"Cindy Winegarden" wrote:
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=VFPOLEDB.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
ci**************@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden

Nov 21 '05 #3
I got the following to work:

Dim myConnection As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=C:\TEMP;Extended Properties=dBase III")
Dim myCommand As New System.Data.OleDb.OleDbCommand("SELECT
OTHWAGE.* FROM OTHWAGE", myConnection)
myConnection.Open()
Dim myReader As System.Data.OleDb.OleDbDataReader =
myCommand.ExecuteReader()
While myReader.Read()
Debug.WriteLine(CStr(myReader.GetValue(0)))
End While
"Cindy Winegarden" wrote:
Hi Joe,

First off, try the FoxPro and Visual FoxPro OLE DB data provider, available


Nov 21 '05 #4
Hi Joe,

I'm glad you found a work-around.

--
Cindy Winegarden MCSD, Microsoft Visual Foxpro MVP
ci**************@msn.com www.cindywinegarden.com
Blog: http://spaces.msn.com/members/cindywinegarden
"genojoe" <ge*****@discussions.microsoft.com> wrote in message
news:ED**********************************@microsof t.com...
I got the following to work:

Dim myConnection As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
Source=C:\TEMP;Extended Properties=dBase III")
Dim myCommand As New System.Data.OleDb.OleDbCommand("SELECT
OTHWAGE.* FROM OTHWAGE", myConnection)
myConnection.Open()
Dim myReader As System.Data.OleDb.OleDbDataReader =
myCommand.ExecuteReader()
While myReader.Read()
Debug.WriteLine(CStr(myReader.GetValue(0)))
End While
"Cindy Winegarden" wrote:
Hi Joe,

First off, try the FoxPro and Visual FoxPro OLE DB data provider,
available

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by PM | last post: by
1 post views Thread by Alfons | last post: by
14 posts views Thread by D. Alvarado | last post: by
reply views Thread by John Winterbottom | last post: by
11 posts views Thread by aldrin | last post: by
1 post views Thread by gangs | last post: by
15 posts views Thread by Umesh | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.