Client applications
LibreOffice
-
Install the Easysoft ODBC-Sybase Driver on same computer as LibreOffice.
-
Choose File > New > Database.
-
Choose Connect to an existing database.
-
Choose ODBC in the list, and then choose Next.
-
Choose Browse, double-click your data source, and then choose Next.
-
If your database requires a database user name, enter it in the User name box. If this user needs to supply a password choose the Password required check box.
-
Choose Finish.
-
Save the database when prompted.
The database opens in a new Base window. From here you can access your data.
-
In the left pane of the database window, choose the Tables icon to display a hierarchy of tables. Enter the database password if prompted, and then choose OK.
-
To retrieve the data in a table, in the Tables pane, double-click a table.
-
Choose the Queries icon to create a query.
Use any of the methods listed in the Tasks pane to create a query.
Oracle
-
Install the Easysoft ODBC-Sybase Driver on same computer as Oracle.
-
Follow the instructions for your Oracle platform.
Connecting Sybase to Oracle on Linux and UNIX
-
Create a DG4ODBC init file on your Oracle machine. To do this, change to the
$ORACLE_HOME\hs\admin
directory. Create a copy of the fileinitdg4odbc.ora
. Name the new fileinitSybase.ora
.In these instructions, replace $ORACLE_HOME
with the location of your OracleHOME
directory. For example,/u01/app/oracle/product/21c/dbhome_1
. -
Ensure these parameters and values are present in your init file:
HS_FDS_CONNECT_INFO = "Sybase"
Replace
Sybase
with the name of your Easysoft ODBC-Sybase Driver data source. -
Comment out the line that enables DG4ODBC tracing. For example:
#HS_FDS_TRACE_LEVEL = <trace_level>
HS_FDS_SUPPORT_STATISTICS = FALSE
The
HS_FDS_SUPPORT_STATISTICS
parameter controls whether Oracle gathers statistics from the Sybase database at the same time as trying to query an ODBC connection. Sybase ASE does not support this behaviour. If you don’t set theHS_FDS_SUPPORT_STATISTICS
parameter toFalse
, you may get an error similar to:General error: connection is busy with results of another hstmt
-
Add an entry to
$ORACLE_HOME/network/admin/listener.ora
that creates aSID_NAME
for DG4ODBC. For example:SID_LIST_LISTENER = (SID_LIST = (SID_DESC= (SID_NAME=Sybase) (ORACLE_HOME=$ORACLE_HOME) (PROGRAM=dg4odbc) (ENVS=LD_LIBRARY_PATH = /usr/local/easysoft/unixODBC/lib: /usr/local/easysoft/lib) ) )
Replace oracle_home_directory with the value of $ORACLE_HOME. For example,
/u01/app/oracle/product/21c/dbhome_1
. -
Add a DG4ODBC entry to
$ORACLE_HOME/network/admin/tnsnames.ora
that specifies theSID_NAME
created in the previous step. For example:Sybase = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = oracle_host)(PORT = 1521)) (CONNECT_DATA = (SID = Sybase) ) (HS = OK) )
Replace
oracle_host
with the host name of your Oracle machine. -
Start (or restart) the Oracle Listener:
cd $ORACLE_HOME/bin ./lsnrctl stop ./lsnrctl start
-
Connect to your Oracle database in SQL*Plus.
-
In SQL*Plus, create a database link for Sybase. For example:
CREATE PUBLIC DATABASE LINK SybaseLink CONNECT TO "dbuser" IDENTIFIED BY "dbpassword" USING 'Sybase';
Replace
dbuser
anddbpassword
with your backend user name and password, if applicable. -
Try querying and updating your Sybase data. For example:
SELECT "Surname" FROM "Customers"@SybaseLink; DECLARE num_rows integer; BEGIN num_rows:=DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@SybaseLink ('INSERT INTO Customers (Surname, GivenName, City, State, Country) VALUES (''Devlin'', ''Michaels'', ''Kingston'', ''NJ'', ''USA'')'); END; / DECLARE num_rows integer; BEGIN num_rows:=DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@SybaseLink ('UPDATE "Customers" SET "Surname" = ''Jones'' WHERE "ID" = ''667'''); END; / DECLARE num_rows integer; BEGIN num_rows:=DBMS_HS_PASSTHROUGH.EXECUTE_IMMEDIATE@SybaseLink ('DELETE from "Customers" WHERE ID = ''667'''); END; /
Notes
-
If you have problems connecting to Sybase from Oracle, enable DG4ODBC tracing and check the trace files written to the
$ORACLE_HOME/hs/trace
directory. To enable DG4ODBC tracing, add the lineHS_FDS_TRACE_LEVEL = DEBUG
toinitSybase.ora
and then start or restart the Oracle listener. If thetrace
directory does not exist, create it.
Go
-
Install the Easysoft ODBC-Sybase Driver on same computer as Go.
-
Install the odbc package for Go:
go mod init test go get github.com/alexbrainman/odbc
-
Create and then use Go to run this script, which retrieves some Sybase data:
package main import ( _ "github.com/alexbrainman/odbc" "database/sql" "log" ) func main() { // Replace the DSN value with the name of your ODBC data source. db, err := sql.Open("odbc", "DSN=Sybase") if err != nil { log.Fatal(err) } var ( name string ) rows, err := db.Query("SELECT Surname FROM Customers") if err != nil { log.Fatal(err) } defer rows.Close() for rows.Next() { err := rows.Scan(&name) if err != nil { log.Fatal(err) } log.Println(name) } err = rows.Err() if err != nil { log.Fatal(err) } defer db.Close() }
Node.js
-
Install the Easysoft ODBC-Sybase Driver on same computer as Node.js.
-
Install the odbc module for Node.js:
npm install odbc
-
Create and then use Node.js to run this script, which retrieves some Sybase data:
const odbc = require('odbc'); // Replace Sybase with the name of your Easysoft ODBC-Sybase Driver // data source. const connection = odbc.connect('DSN=Sybase', (error, connection) => { connection.query('SELECT Surname FROM Customers', (error, result) => { if (error) { console.error(error) } console.log(result); }); });
-
This script retrieves the tables and views in your Easysoft ODBC-Sybase Driver data source:
const odbc = require('odbc'); const connection = odbc.connect('DSN=Sybase', (error, connection) => { connection.tables(null, null, null, null, (error, result) => { if (error) { return; } const util = require('util'); console.log(util.inspect(result, {maxArrayLength: null, depth:null})) }); });
-
This script retrieves the names of the columns in these tables and views:
const odbc = require('odbc'); const connection = odbc.connect('DSN=Sybase', (error, connection) => { connection.columns(null, null, null, null, (error, result) => { if (error) { return; } const util = require('util'); console.log(util.inspect(result, {maxArrayLength: null, depth:null})) }); });
-
These scripts insert, update, and then delete some Sybase data:
const odbc = require("odbc"); const connection = odbc.connect("DSN=Sybase", (error, connection) => { connection.query("INSERT INTO Customers ( Surname, GivenName, City, State, Country ) VALUES ( 'Devlin', 'Michaels', 'Kingston', 'NJ', 'USA' )", (error, result) => { if (error) { console.error(error) } console.log(result); }); }); const odbc = require("odbc"); const connection = odbc.connect("DSN=Sybase", (error, connection) => { connection.query("UPDATE Customers SET Surname = 'Jones' WHERE ID = '667'", (error, result) => { if (error) { console.error(error) } console.log(result); }); }); const odbc = require("odbc"); const connection = odbc.connect("DSN=Sybase", (error, connection) => { connection.query("DELETE FROM Customers WHERE ID = '667'", (error, result) => { if (error) { console.error(error) } console.log(result); }); });
Perl
-
Install the Easysoft ODBC-Sybase Driver on same computer as Perl.
-
Check whether your Perl distribution supports ODBC:
perl -e 'use DBD::ODBC;'
-
Do one of the following:
-
If you get no output, your Perl distribution supports ODBC. Skip to the next step.
-
If you get:
Can't locate DBD/ODBC.pm
you need to install DBD::ODBC before you can use the Easysoft ODBC-Sybase Driver to connect to Sybase.
-
-
Create and then use Perl to run this script, which retrieves some Sybase data:
use strict; use DBI; # Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. my $dbh = DBI-> connect('dbi:ODBC:Sybase'); my $sql = "SELECT Surname FROM Customers"; my $sth = $dbh->prepare($sql) or die "Can't prepare statement: $DBI::errstr"; $sth->execute(); my($Col); # Fetch and display the result set values. while(($Col) = $sth->fetchrow()){ print("$Col\n"); } $dbh->disconnect if ($dbh);
-
This script retrieves the tables and views in your Easysoft ODBC-Sybase Driver data source:
use strict; use DBI; my $dbh = DBI-> connect('dbi:ODBC:Sybase'); my $sth = $dbh->table_info() or die "Can't prepare statement: $DBI::errstr"; my @row; while (@row = $sth->fetchrow_array) { print join(", ", @row), "\n"; } $dbh->disconnect if ($dbh);
-
This script retrieves the names of the columns in these tables and views:
use strict; use DBI; my $dbh = DBI-> connect('dbi:ODBC:Sybase'); my $sth = $dbh->column_info('','','','') or die "Can't prepare statement: $DBI::errstr"; my @row; while (@row = $sth->fetchrow_array) { print join(", ", @row), "\n"; } $dbh->disconnect if ($dbh);
-
These scripts insert, update, and then delete some Sybase data:
use strict; use DBI; my $dbh = DBI-> connect('dbi:ODBC:Sybase'); my $sth = $dbh->prepare(q/INSERT INTO Customers (Surname, GivenName, City, State, Country) VALUES (?, ?, ?, ?, ?)/) or die "Can't prepare statement: $DBI::errstr"; $sth->execute('Devlin', 'Michaels', 'Kingston', 'NJ', 'USA'); $dbh->disconnect if ($dbh); use strict; use DBI; my $dbh = DBI-> connect('dbi:ODBC:Sybase'); my $sth = $dbh->prepare('UPDATE Customers SET Surname = \'Jones\' WHERE ID = ?') or die "Can't prepare statement: $DBI::errstr"; $sth->execute('667'); $dbh->disconnect if ($dbh); use strict; use DBI; my $dbh = DBI-> connect('dbi:ODBC:Sybase'); my $sth = $dbh->prepare('DELETE FROM Customers WHERE ID = ?') or die "Can't prepare statement: $DBI::errstr"; $sth->execute('667'); $dbh->disconnect if ($dbh);
Further information
PHP
-
Install the Easysoft ODBC-Sybase Driver on same computer as PHP.
-
Check whether your PHP distribution supports ODBC. In
php.ini
, make sure there is no comment character (;
) before theextension_dir
andextension=odbc
settings (;extension_dir=directory
becomesextension_dir=directory
and;extension=odbc
becomesextension=odbc
). -
Create and then use PHP to run this script, which retrieves some Sybase data:
<?php // Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. $con = odbc_connect("Sybase", "", ""); $stmt = odbc_exec($con, "SELECT * FROM Customers"); while ($row = odbc_fetch_array($stmt)) { echo "Surname = ", $row["Surname"], "\n"; } odbc_close($con); ?>
-
This script retrieves the tables and views in your Easysoft ODBC-Sybase Driver data source:
<?php $con = odbc_connect("Sybase", '', ''); $tables = odbc_tables($con); while (($row = odbc_fetch_array($tables))) { print_r($row); } odbc_close($con); ?>
-
This script retrieves the names of the columns in these tables and views:
<?php $con = odbc_connect('Sybase', '', ''); $columns = odbc_columns($con); while (($row = odbc_fetch_array($columns))) { print_r($row); } odbc_close($con); ?>
-
These scripts insert, update, and then delete some Sybase data:
<?php $cnx = odbc_connect("Sybase", "", ""); $stmt = odbc_prepare($cnx, "INSERT INTO Customers (Surname, GivenName, City, State, Country) VALUES (?, ?, ?, ?, ?)"); $success = odbc_execute($stmt, array('Devlin', 'Michaels', 'Kingston', 'NJ', 'USA')); odbc_close($cnx); ?> <?php $cnx = odbc_connect("Sybase", "", ""); $stmt = odbc_prepare($cnx, "UPDATE Customers SET Surname = 'Jones' WHERE ID = ?"); $success = odbc_execute($stmt, array('667')); odbc_close($cnx); ?> <?php $cnx = odbc_connect("Sybase", "", ""); $stmt = odbc_prepare($cnx, "DELETE FROM Customers WHERE ID = ?"); $success = odbc_execute($stmt, array('667')); odbc_close($cnx); ?>
Further information
Python
-
Install the Easysoft ODBC-Sybase Driver on same computer as Python.
-
Check whether your Python distribution supports ODBC.
pip list
If you don’t have pip installed:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py python get-pip.py
-
Do one of the following:
-
If the output contains
pyodbc
, your Python distribution supports ODBC. Skip to the next step. -
If the output does not contain
pyodbc
, use pip to install this module:pip install pyodbc
-
-
Create and then use Python to run this script, which retrieves some Sybase data:
import pyodbc # Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. cnxn = pyodbc.connect("DSN=Sybase") cursor = cnxn.cursor() sql = "SELECT Surname FROM Customers" cursor.execute(sql) rows = cursor.fetchall() for row in rows: print(row.Surname) exit()
-
This script retrieves the tables and views in your Easysoft ODBC-Sybase Driver data source:
import pyodbc # Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. cnxn = pyodbc.connect("DSN=Sybase") cursor = cnxn.cursor() cursor.tables() rows = cursor.fetchall() for row in rows: print(row.table_name) exit()
-
This script retrieves the names of the columns in these tables and views:
import pyodbc # Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. cnxn = pyodbc.connect("DSN=Sybase") cursor = cnxn.cursor() cursor.columns() rows = cursor.fetchall() for row in rows: print(row.table_name, row.column_name) exit()
-
These scripts insert, update, and then delete some Sybase data:
import pyodbc cnxn = pyodbc.connect("DSN=Sybase") cursor = cnxn.cursor() sql = "INSERT INTO Customers (Surname, GivenName, City, State, Country) VALUES (?, ?, ?, ?, ?)" cursor.execute(sql, 'Devlin', 'Michaels', 'Kingston', 'NJ', 'USA') cursor.commit() exit()
import pyodbc cnxn = pyodbc.connect("DSN=Sybase") cursor = cnxn.cursor() sql = "UPDATE Customers SET Surname = 'Jones' WHERE ID = ?" cursor.execute(sql, '667') cursor.commit() exit()
import pyodbc cnxn = pyodbc.connect("DSN=Sybase") cursor = cnxn.cursor() sql = "DELETE FROM Customers WHERE ID = ?" cursor.execute(sql, '667') cursor.commit() exit()
Further information
R
-
Install the Easysoft ODBC-Sybase Driver on same computer as R.
-
In R Console, check whether your R distribution supports ODBC.
library("RODBC")
-
Do one of the following:
-
If you get no output, you have the ODBC library for R. Skip to the next step.
-
If you get an "there is no package" error, install the ODBC library for R:
install.packages("RODBC")
-
-
Create and then use R to run this script, which retrieves some Sybase data:
library("RODBC") # Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. ch <- odbcConnect("Sybase") sqlQuery(ch, paste("SELECT Surname FROM Customers")) odbcClose(ch) quit()
-
This script retrieves the tables and views in your Easysoft ODBC-Sybase Driver data source:
library("RODBC") # Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. ch <- odbcConnect("Sybase") sqlTables(ch) odbcClose(ch) quit()
-
This script retrieves the names of the columns in the specified table or view:
library("RODBC") # Replace Sybase with the name of your Easysoft ODBC-Sybase Driver data source. ch <- odbcConnect("Sybase") sqlColumns(ch, sqtable="Customers") odbcClose(ch) quit()
-
These scripts insert, update, and then delete some Sybase data:
library("RODBC") ch <- odbcConnect("Sybase") sqlQuery(ch, paste("INSERT INTO Customers (Surname, GivenName, City, State, Country) VALUES ('Devlin', 'Michaels', 'Kingston', 'NJ', 'USA')")) odbcClose(ch) quit() library("RODBC") ch <- odbcConnect("Sybase") sqlQuery(ch, paste("UPDATE Customers SET Surname = 'Jones' WHERE ID = '667'")) odbcClose(ch) quit() library("RODBC") ch <- odbcConnect("Sybase") sqlQuery(ch, paste("DELETE FROM Customers WHERE ID = '667'")) odbcClose(ch) quit()