How to use ADO with ASP to display Visual FoxPro data (165492)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 3.0
- Microsoft Visual FoxPro for Windows 3.0b
- Microsoft Visual FoxPro for Windows 5.0
- Microsoft Visual FoxPro for Windows 5.0a
- Microsoft Visual FoxPro for Windows 6.0
- Microsoft Visual FoxPro for Windows 7.0
- Microsoft Visual FoxPro 8.0
- Microsoft Visual FoxPro 9.0 Professional Edition
This article was previously published under Q165492
This article assumes that you are familiar with Microsoft Internet
Information Server (IIS) and with creating Active Server Pages (ASP)
applications using the programming tools provided with Microsoft Internet
Information Server or Microsoft Visual InterDev. Additionally, it assumes
that you are familiar with HTML. For more information about Microsoft
Information Server and Active Server Pages, see the following Web
site:
SUMMARY
This article describes how to use ActiveX Data Objects (ADO) on an Active
Server Page (ASP) to access data in a Microsoft Visual FoxPro database.
MORE INFORMATION
To run Active Server Pages, you must have access to a computer
that is running Microsoft Internet Information Server (IIS) version 3.0 or a later version of IIS.
To access a Visual FoxPro database through ADO, you must have the
latest Visual FoxPro ODBC driver.
For additional information about how to obtain this driver, click the following article number to view the article in the Microsoft Knowledge Base:
277772
Visual FoxPro ODBC Driver not included in MDAC 2.6 and later
Note If your database or tables use any of the features that were introduced in Visual FoxPro 7.0 or a later version of Visual FoxPro, you must use the VFP OLE DB Provider to connect to the data. To obtain the VFP OLE DB Provider, visit the following Microsoft Developer Network (MSDN) Web site: To set up ODBC to access your database over the
Internet Information Server, use one of the following methods: - Create a System Data Source on the IIS Server computer that points to
the database.
- Create a File Data Source that points to the database. If you create
this Active Server Page in a Database Project in Visual InterDev Studio,
if you add a connection that uses a file data source, it includes the
data source information in the Global.asa file. This can then be
distributed with the Active Server Page.
- When creating the connection object through VBScript, include the
connect string when running the Open method (example below).
Limitations
Recordsets, or cursors, generated by Visual FoxPro through the Visual
FoxPro ODBC Driver must be of type STATIC, or READONLY. The Visual FoxPro
ODBC driver does not support the KEYSET, or DYNAMIC cursor types.
Example
This example does not use a specific data source. The connect string is
being specified in the connection object's Open method. If you do wish to
create and use a Data source, ensure it is a System Data Source on the
Microsoft Internet Information Server computer.
Remember
Change the SourceDB setting to reflect the Tastrade.dbc on the test system.
Ensure the Visual FoxPro ODBC driver version 6.01.8629.01 or later is installed on the
Microsoft Information Server where this Active Server Page is stored.
Please see article reference above for availability options of this driver.
Contents of the ASP page
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<TITLE>VFP ASP ADO Test</TITLE>
</HEAD>
<BODY>
<H3>ActiveX Data Object (ADO)</H3>
<%
Set Conn = Server.CreateObject("ADODB.connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver; " + _
"UID=;SourceType=DBC;SourceDB=C:\VFP\Samples\Tastrade\Data\Tastrade.dbc"
Conn.Open ConnStr 'This can be a datasource name or a connect string
Set cmdTemp = Server.CreateObject("ADODB.Command")
Set rs = Server.CreateObject("ADODB.Recordset")
SQLText="Select Distinct Products.Product_ID,Products.Product_Name,"+ _
"Products.English_Name,Products.Unit_Price, " + _
"Products.Quantity_In_Unit from Tastrade!Products"
cmdTemp.CommandText = SQLText
cmdTemp.CommandType = 1 'SQL statement
Set cmdTemp.ActiveConnection = Conn
rs.CacheSize = 10
rs.Open cmdTemp,,adopenstatic
%>
<P>
<TABLE BORDER=1>
<TR>
<% For i = 0 to RS.Fields.Count - 1 %>
<TD><B><% = RS(i).Name %></B></TD>
<% Next %>
</TR>
<% Do While Not RS.EOF %>
<TR>
<% For i = 0 to RS.Fields.Count - 1 %>
<TD VALIGN=TOP><% = RS(i) %></TD>
<% Next %>
</TR>
<%
RS.MoveNext
Loop
RS.Close
Conn.Close
%>
</TABLE>
<BR>
<BR>
</BODY>
</HTML>
REFERENCES
Additional information on Active Data Object can be found in the following
sources:
Modification Type: | Minor | Last Reviewed: | 3/8/2005 |
---|
Keywords: | kbDatabase kbhowto kbinterop KB165492 kbAudDeveloper |
---|
|