Microsoft KB Archive/130465

= How To Connect to a Different Database Using ODBC =

Article ID: 130465

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.6 Standard Edition
 * Microsoft FoxPro 2.6a Standard Edition
 * Microsoft Visual FoxPro 3.0b for Macintosh

-



This article was previously published under Q130465



SUMMARY
When a connection is made to a SQL Server data source, the database in use will be:


 * The one specified in the data source.

-or-
 * The default database as defined on the server - if there isn't one specified in the data source,

The database in use can be changed by using ODBC and executing a USE command within the SQLEXEC function. Or if you're using FoxPro version 2.x for Windows, you can use the DBEXEC function.

The initial database in use can be specified in the data source by going into the setup of the data source, clicking the Options button, and typing in the name of the database in the "Database Name" area.



MORE INFORMATION
Assuming a connection exists to a SQL Server data source, the database in use can be changed by executing the following function: success = SQLEXEC(handle,"USE ") This cannot be used reliably with Remote Views created from saved Connections because there is no reliable way to determine the connection handle obtained from the DataSource or a saved Connection. To connect to a DataSource and obtain a handle number, use the SQLConnectfunction in Visual FoxPro or the DBConnect function in FoxPro version 2.x for Windows.

Keywords: kbhowto kbinterop KB130465

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.