Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Microsoft: FoxPro FAQ

Client-Server and ODBC

How do you connect to remote data sources via ODBC? by foxdev
Posted: 7 Jun 00

Creating Connections

Before you can retrieve or update data on a database server or other ODBC source such as Access, you must establish a connection. This applies whether you are using SQL pass-through (SPT) or a remote view.  When you USE a remote view, a connection using the name connected you previously defined is automatically established.  You must explicitly establish a connection before using one or more SQL pass-through statements.

A connection usually involves identifying a server, a database, a username and a password. Connections can be named and stored in a database container so that you can reconnect later by specifying the connection name, or they can be created on-the-fly through a command.

A named connection can be created by issuing the command CREATE CONNECTION while you have a database container open. You will be presented with a dialog allowing you to pick the ODBC data source, username, and so forth. When you save it, you'll be asked to enter a name; you can use that name later to establish a connection, or it can be used as a connection by any remote views you create.

Once you have created a named connection, it can be used for both remote views and SQLCONNECT().

Establishing Connections

You will only need to manually establish a connection if you are using SQL pass-through.  Opening a remote view will automatically establish a connection, so there is no need to use these methods described below with remote views.

To establish a connection using an existing named connection, open the database container (you can issue the command OPEN DATABASE MyDatabase to do that) and issue the command:


where "myconnection" is the name of the connection you've created. Note that we've stored the connection handle returned to us by SqlConnect() in the memvar nConnect for use later.

Connections can also be created that do not need to be stored in a database container. These will need to contain all the information necessary to establish the connection each time.

One way to establish a connection dynamically is with SQLSTRINGCONNECT().  For example, issue the command:


An alternative to using the "driver=" method is to use the "dsn=" parameter, where the DSN (data source name) is one found in your Control Panel/32-bit ODBC User DSN section.

Another way to establish a connection without having a named connection in a DBC is by using SQLCONNECT() and specifying a DSN defined in your ODBC.INI, such as:


The user name and password are optional if you've already defined them in the ODBC DSN setup.

Back to Microsoft: FoxPro FAQ Index
Back to Microsoft: FoxPro Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close