![]() | ![]() |
Home |
|
|
ASA User's Guide |
|
| Part 1 Working with Databases |
|
| Chapter 2: Connecting to a Database |
|
| Simple connection examples |
Although the connection model for Adaptive Server Anywhere is configurable, and can become complex, in many cases connecting to a database is very simple.
This section describes some simple cases of applications connecting to an Adaptive Server Anywhere database. This section may be all you need to get you started.
For more detailed information on available connection parameters and their use, see Connection parameters .
Many examples and exercises throughout the documentation start by connecting to the sample database from Interactive SQL.
To connect to the sample database from Interactive SQL:Start Interactive SQL
You can do this as follows:
From the Windows 95 or Windows NT Start menu, choose Sybase -->-->Adaptive Server Anywhere -->-->Interactive SQL.
In Windows 3.x, chose Interactive SQL from the Adaptive Server Anywhere program group.
Type
dbisqlat a system command prompt.
A connection window appears.
Connect
From the ODBC data source list, select ASA 6.0 Sample. You can leave all the other fields empty. Click OK to start the database server and connect to the database.
An embedded database, designed for use by a single application, runs on the same machine as the application and is largely hidden from the application user.
When an application uses an embedded database, the personal server is generally not running when the application connects. In this case, you can start the database using the connection string, and by specifying the database file in the DatabaseFile (DBF) parameter of the connection string.
The DBF parameter specifies which database file to use. The database file automatically loads onto the default server, or starts a server if none is running.
The database unloads when there are no more connections to the database (generally when the application that started the connection disconnects). If the connection started the server, it stops once the database unloads.
The following connection parameters show how to load the sample database as an embedded database:
dbf=path\asademo.db uid=dba pwd=sql
where path is the name of your Adaptive Server Anywhere installation directory.
The following connection parameters show how you can customize the startup of the sample database as an embedded database. This is useful if you wish to use command-line options, such as the cache size:
Start=dbeng6 -c 8M dbf=path\asademo.db uid=dba pwd=sql
Extra cache needed for Java
If you are using Java in an embedded database, you should use the start line to provide more than the default cache size. For development purposes, a cache size of 8 Mb is sufficient.
In this example, the sample database is an embedded database within Interactive SQL.
To connect to an embedded database from Interactive SQL:Start Interactive SQL with no databases running. You can use either of the following ways:
From the Windows 95 or Windows NT Start menu, choose Sybase -->-->Adaptive Server Anywhere -->-->Interactive SQL.
In Windows 3.x, chose Interactive SQL from the Adaptive Server Anywhere program group.
Type
dbisqlat a system command prompt.
When Interactive SQL starts, it is not connected to any database.
Type CONNECT in the command window, and press F9 to execute the command. The connection dialog appears.
If you have an ODBC data source for your database, select that data source.
Enter
DBAas the user ID and
SQLas the password. Then click the Database tab. Enter the full path of the sample database in the Database File field. For example, if your installation directory is c:\sybase\asa6 you should enter the following:
c:\sybase\asa6\asademo.db
Leave all other fields blank, and click OK. Adaptive Server Anywhere starts up and loads the sample database, and Interactive SQL connects to the database.
You can save sets of connection parameters in a data source. ODBC and Embedded SQL applications use data sources. You can create data sources from the ODBC Administrator.
Here, we show how to connect to the sample database from Interactive SQL using a data source
To connect using a data source:Start Interactive SQL with no databases running. You can:
Type
dbisqlat a system command prompt, or
From the Windows 95 or Windows NT Start menu, choose Sybase-->Adaptive Server Anywhere-->Interactive SQL, or
In Windows 3.x, chose Interactive SQL from the Adaptive Server Anywhere program group.
When Interactive SQL starts, it is not connected to any database.
Type CONNECT in the command window, and press F9 to execute the command. The connection dialog appears.
Enter
DBAas the user ID and
SQLas the password. Select
ASA 6.0 samplefrom the drop-down list of ODBC data sources.
Leave all other fields blank, and click OK. Adaptive Server Anywhere starts up and loads the sample database, and Interactive SQL connects to the database.
The ASA 6.0 Sample data source holds a set of connection parameters, including the database file and a Start parameter to start the database.
To connect to a database running on a network server somewhere on a local or wide area network, the client software must locate the database server. Adaptive Server Anywhere provides a network library (a DLL or shared library) to handle this task.
Network connections occur over a network protocol. Several protocols are supported, including TCP/IP, IPX, and NetBIOS.
For a full description of client/server communications over a network, see Client/Server Communications .

Adaptive Server Anywhere server names must be unique on a local domain for a given network protocol. The following connection parameters provide a simple example for connecting to a server running elsewhere on a network:
eng=svr_name dbn=db_name uid=user_id pwd=password CommLinks=all
The client library first looks for a personal server of the given name, and then looks on the network for a server of the given name.
The above example finds any server started using the default port number. However, you can start servers using other port numbers by providing more information in the CommLinks parameter. For information, see CommLinks connection parameter .
If several protocols are available, you can instruct the network library which ones to use to improve performance. The following parameters use only the TCP/IP protocol:
eng=svr_name dbn=db_name uid=user_id pwd=password CommLinks=tcpip
The network library searches for a server by broadcasting over the network which can be a time-consuming process. Once the network library locates a server, the client library stores its name and network address in a file, and reuses this entry for subsequent connection attempts to that server using the specified protocol. Subsequent connections can be many times faster than a connection achieved by broadcast.
Many other connection parameters are available to assist Adaptive Server Anywhere in locating a server efficiently over a network. For more information see Network communications parameters .
You can leave many connection parameters unspecified, and instead use the default behavior to make a connection. Be cautious about relying on default behavior in production environments, especially if you distribute your application to customers who may install other Adaptive Server Anywhere applications on their machine.
If a single personal server is running, with a single loaded database, you can connect using entirely default parameters:
uid=user_id pwd=password
If more than one database is loaded on a single personal server, you can leave the server as a default, but you need to specify the database you wish to connect to:
dbn=db_name uid=user_id pwd=password
If more than one server is running, you need to specify which server you wish to connect to. If only one database is loaded on that server, you do not need to specify the database name. The following connection string connects to a named server, using the default database:
eng=server_name uid=user_id pwd=password
The following connection string connects to a named server, using a named database:
eng=server_name dbn=db_name uid=user_id pwd=password
For more information about default behavior, see Troubleshooting connections .
All Adaptive Server Anywhere database utilities that communicate with the server (rather than acting directly on database files) do so using Embedded SQL. They follow the procedure outlined in Troubleshooting connections when connecting to a database.
Many of the administration utilities obtain the connection parameter values by:
Using values specified on the command line (if there are any). For example, the following command starts a backup of the default database on the default server using the user ID
DBAand the password
SQL:
dbbackup -c "uid=dba;pwd=sql" c:\backup
Using the SQLCONNECT environment variable settings if any command line values are missing. Adaptive Server Anywhere doesnot set this variable automatically.
For a description of the SQLCONNECT environment variable, see Environment variables .
Prompting you for a user ID and password to connect to the default database on the default server, if parameters are not set in the command line, or the SQLCONNECT environment variable,
For a description of command line switches for each database tool, see chapter Database Administration Utilities .
|
|