Collection Contents Index CHAPTER 2.  Connecting to a Database Simple connection examples pdf/chap2.pdf

User's Guide
   PART 1. Working with Databases
     CHAPTER 2. Connecting to a Database       

Introduction to connections


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.

How connections are established 

To establish a connection, the client application calls functions in one of the Adaptive Server Anywhere interfaces. Adaptive Server Anywhere provides the following interfaces:

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.

What to read 

If you want...

Consider reading...

Some examples to get started quickly

Simple connection examples.

To learn about data sources

Working with ODBC data sources

To learn what connection parameters are available

Connection parameters.

To see an in-depth description of how connections are established

How connections are made.

Top of page  Connection parameters specify connections

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

Representing connection strings 

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.

Top of page  Connection parameters are passed as connection strings

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    
Interactive SQL processes the connection string internally. These utilities do not simply pass on the connection parameters to the interface library. Do not use Interactive SQL to test command strings from a command prompt.

Top of page  

Collection Contents Index CHAPTER 2.  Connecting to a Database Simple connection examples pdf/chap2.pdf