Chapter Contents |
Previous |
Next |
CONNECT Statement |
Syntax | |
Arguments | |
DB2 Connection Arguments | |
CONNECT Examples |
Syntax |
CONNECT TO DB2 <AS alias> <(DB2-connection-arguments)>; |
Use the following arguments with the CONNECT statement:
DB2 Connection Arguments |
You must specify the PROC SQL CONNECT statement when you connect to DB2. You can connect to only one DB2 database at a time; however, you can use multiple CONNECT statements to connect to multiple DB2 data sources by using the alias argument to distinguish your connections.
The following list describes the arguments that are used for DB2 in the CONNECT statement. You can use the arguments DATABASE=, USER=, and PASSWORD= to connect to most data sources. Use the PROMPT=, NOPROMPT=, COMPLETE=, REQUIRED=, or AUTOCOMMIT= arguments to provide additional information or to select and connect to the data source.
There are multiple ways that you can connect to the DBMS when using the CONNECT statement. Use only one of the following methods for each connection since they are mutually exclusive:
The USER= and PASSWORD= connections are optional in DB2. If you specify USER=, you must also specify PASSWORD=.
The USER= and PASSWORD= connection options are optional in DB2 because users may have default user IDs. If you specify USER=, you must specify PASSWORD=.
If AUTOCOMMIT=YES, no rollback is possible. This is the default for the SQL Procedure Pass-Through Facility and read-only connections.
If AUTOCOMMIT=NO, the SAS/ACCESS engine automatically does the commit when it reaches the end of the file.
COMPLETE= is similar to the PROMPT= option. However, if COMPLETE= attempts to connect and fails, then a dialog box is displayed and you can edit values or enter additional values.
COMPLETE= is optional.
See your driver documentation for more details.
A dialog box is displayed, using the values from the PROMPT= connection string. You can edit any field before you connect to the data source. When a successful connection is made, the complete connect string is returned in the SYSDBMSG and SQLXMSG macro variables.
PROMPT= is similar to the COMPLETE= option. However, unlike COMPLETE=, PROMPT= does not attempt to connect to the DBMS first. It displays the dialog box where you can edit or enter additional values.
If you specify enough correct connection options, such as user ID, password, and data source name, the SAS/ACCESS engine connects to the data source or database. Otherwise, a dialog box is displayed to prompt you for the connection options. Options in the dialog box that are not related to the connection are disabled. REQUIRED= only allows you to modify required fields in the dialog box. When a successful connection is made, the complete connect string is returned in the SYSDBMSG and SQLXMSG macro variables.
REQUIRED= is similar to COMPLETE= because it attempts to connect to the DBMS first. However, if REQUIRED= attempts to connect and fails, then a dialog box is displayed and you can only edit values in the required fields.
REQUIRED= is optional.
CONNECT Examples |
The following example connects to the SAMPLE database and sends it two EXECUTE statements to process.
proc sql; connect to db2 (database=sample); execute (create view sasdemo.whotookorders as select ordernum, takenby, firstname, lastname, phone from sasdemo.orders, sasdemo.employees where sasdemo.orders.takenby= sasdemo.employees.empid) by db2; execute (grant select on sasdemo.whotookorders to testuser) by db2; disconnect from db2; quit;
The next example connects to the SAMPLE database by using an alias (DB1) and performs a query, shown in italic type, on the SASDEMO.CUSTOMERS table.
proc sql; connect to db2 as db1 (database=sample); select * from connection to db1 (select * from sasdemo.customers where customer like '1%'); disconnect from db1; quit;
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.