Skip to main content

How to connect to Oracle database in SAS?


In my project, our client widely use Oracle database for their data. I hope Oracle is widely used database. So here I will explain making connection from SAS to Oracle database, my routine activity. Also, you will find the common issues and how to rectify them.

Exploring tnsnames.ora

To make connection to Oracle database, we should make an entry in tnsnames.ora. The tnsnames.ora file will be inside Oracle DB client installation drive. By default installation directory and tnsnames.ora file will be in /base-directory/oracle/product/11.2.0/client_1/network/admin/tnsnames.ora
Base-directory = Can be any directory.

What will be inside tnsnames.ora file?

The tnsnames.ora file is a configuration file for Oracle client which holds information about the server. To make it simple, your machine needs to contact another machine and this entry holds the address of another machine. So what does the address will look like? The below image is the sample tns entry.

TNS entry with schema name CHSLKJE
In above image, only the service-name, ip address and port number varies for each entry. The service name is also known as schema or SID of Oracle database.

How to check whether the entry is correct?

Oracle client has a utility called tnsping. Using tnsping you can ping the database. The output will be success if the entry is right or it will show error messages like Timed Out etc.

You need to set environment variable to run this command. Without environment variable you will get the error - tnsping: command not found. Comment below if you need to know the environment variable of you system.

Other methods:

You can run LIBNAME statement for Oracle database in SAS Enterprise Guide to check the entry. If the library get assigned then the entry is correct.  

Comments

Popular posts from this blog

How to create library for Oracle in SAS?

In this article, you will get details about creating a new library using SAS Management Console. Here, I have provided the procedure for creating library for Oracle database. However, the steps will be same for other databases like SQL server, Teradata etc.     Creating connection to Oracle database: To create library, you must first create a connection to Oracle database in your host machine. Host machine is the physical location where your SAS platform is installed. Details like Oracle database hostname/IP address and DSN/SID name is needed. Those details should be entered in tsnnames.ora file. For more details check this article Creating library in SAS Management Console: The steps for creating library for Oracle using SAS Management Console (SMC) can used for other database like SQL Server, My SQL etc. New library wizard: Expand Data Library Manager plug-in, right click on the Libraries and click New Library to start library wizard.  You will be asked

SAS - CLI error trying to establish connection

Issue: User asked me to make a database connectivity to SQL Server. They provided following details SQL server hostname and ip address Database/DSN name Username Password I made entry in ODBC.ini file. You know, SQL Server entries were made in ODBC.ini and Oracle entries were made in TNS.ora file. Everything went fine, took back up of odbc.ini, made entry and saved the file. So to test this connection I ran the libname statement in SAS Enterprise Guide 6.1. It throwed following error. Error Message: My DB team showed that they are able to login   14 GOPTIONS ACCESSIBLE; 15 LIBNAME test ODBC DATASRC=SGE_DS SCHEMA=VST USER=sales PASSWORD=XXXXXXXXX; ERROR: CLI error trying to establish connection: [SAS/ACCESS to SQL Server][ODBC SQL Server Legacy Driver][SQL Server]Login failed for user 'sales'. Solution: First I suspected that Login failed for user 'sales' meant the password provided by DB team was wrong. They responded that they were able to login wi

Insufficient authorization to access PIPE error in SAS EG

Issue: When I tried to run SAS code in SAS Enterprise Guide it throws following errors: ERROR: Insufficient authorization to access PIPE. ERROR: Error in the FILENAME statement. Screenshot of error: Solution: This error occurs when you try to run OS commands in SAS code. To run the OS commands in SAS code you need to enable XCMD option. You check it in SAS Management Console by following below steps.   Open SMC -> Expand Servers -> Expand   In SASApp , expand Logical Workspace Server -> right click on Workspace Server. Click properties -> option tab -> advanced options -> launch properties. Check whether Allow XCMD is checked. The issue arises if the Allow XCMD is not checked. In above image, Allow XCMD option is not checked. It should be checked to run OS commands from SAS code. In Unix /Linux machines, this XCMD option can be enabled by using system option XCMD in sasv9 config file or workspaceserver.sh script file. Us