ASP.NET And Legacy MS-DOS Applications

I'm currently studying FoxPro 2.6. For MS-DOS. Yes, the company I am working for is still using applications written for FoxPro 2.6! I have to run this old MS-DOS database system in Virtual PC. So the last programming book I've read was Charles Siegel's Mastering FoxPro 2 written in 1991. The applications are completely undocumented (grrrr!) so my first step was to create a data dictionary (aka database schema). In FoxPro this can be done through the command DISPLAY STRUCTURE.

However, it is possible to connect to these old MS-DOS FoxPro database files using ASP.NET. First you will need the Microsoft OLE DB Provider for Visual FoxPro 9.0. It is important to realize that every table in a FoxPro database exists within its own DBX file with maybe a CDX file for the index. So to access a particular table you actually need to access a particular file location. I had to create folders for each table database and then set the data source as a folder:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Data.Odbc;

public partial class FoxPro_Query : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            OleDbConnection cn = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=C:\\Projects\\FoxPro\\WZ\\CLIENT;Collating Sequence=general;");
            OleDbDataAdapter da = new OleDbDataAdapter("SELECT subid, fund_src, lname, fname, addr1, addr2, city, state, zip, phone_h, county, homeowner, notes, directions FROM CLIENT WHERE Lname = 'ROBBINS'", cn);
            DataTable objDataTable = new DataTable();
            da.Fill(objDataTable);

            GridView1.DataSource = objDataTable;
            GridView1.DataBind();

            cn.Close();
        }
        catch (OleDbException ode)
        {
            lblErrorMessage.Text = ode.ToString();
        }
    }
}

It is also possible to get the schema of the FoxPro database table and bind it to a GridView for a web page version of the database structure. 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.OleDb;
using System.Data.Odbc;

public partial class FoxPro : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            OleDbConnection cn = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=C:\\Projects\\FoxPro\\WZHSTDET;Collating Sequence=general;");
            cn.Open();
            DataTable objDataTable = new DataTable();
            objDataTable = cn.GetSchema("Columns");

            GridView1.DataSource = objDataTable;
            GridView1.DataBind();

            cn.Close();
        }
        catch (OleDbException ode)
        {
            lblErrorMessage.Text = ode.ToString();
        }
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[2].Text = Enum.GetName(typeof(OleDbType), Convert.ToInt32(e.Row.Cells[2].Text));
        }
        
    }
}

Hopefully this is just the first step in getting these applications off of MS-DOS FoxPro 2.6 and onto a more contemporary development framework. The current system seems to give its users a lot of headaches.

No Comments