User's Guide
PART 1. Working with Databases
CHAPTER 2. Connecting to a Database
Any client application that uses a database must establish a connection to that database before any work can be done.
Once the connection is established, it forms a channel through which all of your activity from the client application takes place. For example, your permissions to carry out actions on the database are determined by your user ID—and the database server has your user ID because it is part of the request to establish a connection.
To establish a connection, the client application calls functions in one of the Adaptive Server Anywhere interfaces. Adaptive Server Anywhere provides the following interfaces:
ODBC ODBC connections are discussed in this chapter.
Embedded SQL Embedded SQL connections are discussed in this chapter.
Sybase Open Client Open Client connections are not discussed in this chapter. For information on connecting from Open Client applications, see Adaptive Server Anywhere as an Open Server.
JDBC JDBC connections are not discussed in this chapter. For information on connecting via JDBC, see Data Access Using JDBC.
The interface uses connection information included in the call from the client application, perhaps together with information held on disk in a file data source, to locate and connect to a server running the required database. The following figure is a simplified representation of the pieces involved.
If you want... |
Consider reading... |
---|---|
Some examples to get started quickly |
|
To learn about data sources |
|
To learn what connection parameters are available |
|
To see an in-depth description of how connections are established |
When an application connects to a database, it uses a set of connection parameters to define the connection. Connection parameters include information such as the server name, the database name, and a user ID.
Each connection parameter is specified as a keyword-value pair, of the form parameter=value. For example, the password connection parameter for the default password is specified as follows:
Password=sql
Connection parameters are assembled into connection strings. In a connection string, each connection parameter is separated by a semicolon, as follows:
ServerName=asademo;DatabaseName=asademo
This chapter has many examples of connection strings. For ease of reading, connection parameters in this chapter are generally represented in the following form:
parameter1=value1 parameter2=value2 ...
This is equivalent to the following connection string:
parameter1=value1;parameter2=value2
A connection string must be entered on a single line, with the parameter settings separated by semicolons.
Connection parameters are passed to the interface library as a connection string. This string consists of a set of parameters, separated by semicolons:
parameter1=value;parameter2=value2;...
In general, the connection string built up by an application and passed to the interface library does not correspond directly to the way a user enters the information. Instead, a user may fill in a dialog box, or the application may read connection information from an initialization file.
Many of the Adaptive Server Anywhere utilities accept a connection string as the -c command-line option and pass the connection string on to the interface library without change. For example, the following is a typical Collation utility (dbcollat) command line (which should be entered all on one line):
dbcollat -c "uid=dba;pwd=sql;dbn=asademo" c:\temp\asademo.col
Interactive SQL connection strings |