Can you connect using the ODBC interface without setting up a datasource?

0 Likes

Problem:

Can you connect to a database using ODBC without configuring a Data Source Name (DSN) ?

Can I connect to SQL Server without using a DSN?

Can I connect to Oracle without using a DSN?

How do you use ODBC connection strings?

Using an ODBC connection string, a -19703 error occurs on the CONNECT statement.

Resolution:

Yes, by using a connection string, this doesn't require a datasource name  (DSN) to be set up on the target workstation.

The connection string and parameters differ for each driver.

For the driver name, use the name that appears in the left-most column of the drivers tab in the ODBC control panel.

For other connect string options, look up "SQLDriverConnect"  or "Connection String" in the help file for the driver. You access the help file by starting to set up a DSN and then clicking the help button. There may be other options tha you set up through the configuration of a data source that you need to specify in the connect string.

The following is an example using the Microsoft SQL Server ODBC driver for connection to the pubs database on MYSERV server with a userid of sa and a password of pwd.

       01  connectString               PIC X(128) VALUE

              'DRIVER=Sql Server;UID=sa;PWD=pwd;DATABASE=pubs;'

              &'SERVER=MYSERV'.

          EXEC SQL

               CONNECT USING :connectString

          END-EXEC

If the DRIVER element of the connection string is not correct, you may receive an -19703 SQLCODE error on executing the CONNECT statement.

Old KB# 6884
Comment List
Related
Recommended