Chapter 14 : Microsoft FoxPro Connectivity Kit
Microsoft FoxPro Support Engineers
Microsoft Corporation
Created: December 15, 1993
Abstract
The following text discusses the Microsoft FoxPro Connectivity Kit (CK) version 2.5 and its use with FoxPro for Windows version 2.5x.
This section is broken down as follows:
·	Introduction
·	Open DataBase Connectivity (ODBC)
·	CK components for FoxPro for Windows version 2.5x
·	Using the CK
·	Trouble-shooting 
·	Additional Information About the CK
Introduction
The CK enables FoxPro for Windows version 2.5x to be used as a "front end" to ODBC compliant SQL server software. A FoxPro interface can programatically pass SQL statements to the SQL server or SQL data source of choice.
There is only one CK for both the Windows and MS-DOS products. However, the components for each of these environments differ. The Microsoft Windows component of the CK ships with drivers for SYBASE, Microsoft SQL Server and Oracle.
Open DataBase Connectivity (ODBC)
ODBC is a standard that has evolved to ease the burden of accessing information from various database management systems (DBMS). ODBC is vendor neutral, allowing access to multiple DBMS's from multiple ODBC aware applications. With the ODBC standard, data source vendors need only to supply their product specific software and an ODBC driver. This driver contains specific instructions that allow their products to communicate with other ODBC aware products.

CK Components for FoxPro for Windows version 2.5x
Below is a diagram of the elements necessary to establish a communication channel between FoxPro for Windows and an ODBC compliant SQL server.

		

More information on Data Source
Each data source has it's own unique data source driver. ORACLE.DLL and SQLSVR.DLL are provided with the CK. The Data Source is set up in the Control Panel\ODBC icon. The information which is requested for the driver must be complete and accurate in order to ensure a connection. 
A list of third-party ODBC drivers is included in the Reference section of this Resource Kit. This is by no means an exhaustive list. If you are currently using a SQL data source or are interested in purchasing one, contact the software vendor to see if they provide ODBC drivers for their product.
The CK provides CKSAMPLE.APP and it's source code that gives you a working example of how to interface with your ODBC compliant data source. 
Using the CK
Here is a list of things to keep in mind when using the CK:
	CK cannot Rushmore optimize your SQL statements on your SQL data source. With the addition of the CK, FoxPro becomes the "mail carrier" to your data source. We simply pass the message to the data source. The data source is responsible for the execution of the command.
	CK cannot pass FoxPro specific commands and functions to your data source for execution. For example, we cannot send a BROWSE command via the DBExec() function to browse information on your data source.
	The length of the SQL statements passed to the data source are limited to 255 characters.
Trouble-shooting
This section will discuss trouble-shooting error messages encountered when using the CK. Errors will be broken down into two sections: FoxPro errors and ODBC errors.
FoxPro Error messages
API Library Not Found
This error will be returned by the SET LIBRARY TO FPSQL.FLL command if it is not successful. Check to ensure you have specified the correct path to FPSQL.FLL. If so, this file could be damaged and will need to be reinstalled from the original diskettes.
File ‘dbconnect.prg’ does not exist
This error is returned by issuing a =DBConnect() command before issuing a SET LIBRARY TO FPSQL.FLL command.
Other FoxPro error messages
Use standard techniques to trouble-shoot other error messages such as checking the error listing in the Developer’s Guide.
TIP:     If you are using Technet or MSDN, search through the Knowledge Base section for the exact error message.
ODBC Error Messages
Below is a break-down of the ODBC error message followed by a sample program using DBError() to capture the exact error message.
Error message format:
[VENDOR][ODBC-COMPONENT][Data Source] "<Error Message>"
ODBC error message
Element	Meaning	
vendor-identifier	Identifies the vendor of the component in which the error occurred or that received the error directly from the data source.	
ODBC-component identifier	Identifies the component in which the error occurred or that received the error directly from the data source.	
data source identifier	Provides the name of the data source. This may not always be present in the error message. If this is specified in the error, the connection has been made to the data source, and an error has occurred after that connection has been established.	
error message text	Text string describing error message	

DBError() routine
The DBError() function uses the handle returned by DBConnect() to determine the source of the error. DBError() returns a numeric error type. This error type can be quite helpful in determining the source of the error.
NOTE:     DBConnect() can return different values for the connection handle. If the value is 1 or greater, a connection has been established successfully. A value of 0 indicates that the function is still executing. A value of -1 indicates an error at the connection level and a value of -2 indicates an error at the environment level (DOS/Windows).
To obtain the exact error message and a value for DBError():
handle=DBConnect(“data_source_name”,”user_id”,”password”,”connect_string”)
errmsg=“”
errno=0
if handle<0
	do case
		case handle=-1
			errtype=DBError(handle,@errmsg,@errno)
		case handle=-2
			errtype=DBError(0,@errmsg,@errno)
	endcase
endif
?errtype		&&Returns DBError() value. See chart below.
?errmsg		&&Returns complete error message in ODBC error message format.
				&&Use charts 11A and 11B to troubleshoot error.
?errno		&&Returns source-specific error number. Consult source
				&&documentation for additional information about the 
				&&error number and error message.

The values which might be returned into errtype above are:
DBError() Values
Value	Error Class	Platform	
0	No Error	Windows, MS-DOS	
1	FoxPro Error	Windows, MS-DOS	
2	FPSQL(.PLB or .FLL) error	Windows, MS-DOS	
3	Data Source Error (ODBC)	Windows	
4	DB-Library Error (MS-DOS)	MS-DOS	
5	SQL Server Error (MS-DOS)	MS-DOS	
-2	Environment Level Error (MS-DOS/Windows)	Windows, MS-DOS	
Additional Information About CK
Additional information concerning the use of the CK can be found by looking at the following articles:

Q101806	Q103576	Q104342	
Q103142	Q103578