Over a million developers have joined DZone.

Using Advantage data providers to read DBF-files

DZone 's Guide to

Using Advantage data providers to read DBF-files

· ·
Free Resource

In one of my projects I have to read FoxPro DBF-files and import data from them. As this code must run in server and customer doesn’t want to install FoxPro there we found another solution that seems at least to me way better. In this posting I will show you how to read DBF-files using Sybase Advantage data providers.

Getting Advantage data providers

Here are the download links to data providers:

I downloaded and installed .NET data provider and my example here is fully based on this.

Configuring application

Advantage Data provider test application

If you run application without configuring some data providers stuff before you will get the following error:

Error 5185: Local server connections are restricted in this environment. See the 5185 error code documentation for details.

Go to your application bin folder and add there usual text file called ads.ini. Here is the content for this file:


Make sure you add reference to Advantage data provider assembly and include ads.ini to your project like shown on image above.

Getting data to DataTable

Here is short code example about how to get data from DBF-file to DataTable.

static void Main(string[] args)
    var connStr = "data source={0};tabletype=vfp;servertype= local;";
    connStr = string.Format(connStr, "c:\\temp\\");
    var table = new DataTable();
    using (var conn = new AdsConnection(connStr))           
    using (var adapter = new AdsDataAdapter())
    using (var cmd = new AdsCommand())
        cmd.Connection = conn;
        cmd.CommandText = "select * from " + tableName;
        adapter.SelectCommand = cmd;

    Console.WriteLine("Table fields:");
    foreach (DataColumn col in table.Columns)
    Console.WriteLine(" ");
    Console.WriteLine("Rows: " + table.Rows.Count);

If Advantage data providers were installed correctly and there are no errors in table names, locations and your SQL query then you should see list of table column names and row count on console window when you run the application.


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}