Skip to Content
Technical Articles

go-ase: an open source ASE database driver for the Go programming language


This blog post is outdated. Meanwhile there are two Go SQL drivers available for SAP ASE:

  1. This is the pure go driver directly connecting to the ASE using the TDS protocol.
  2. This is the cgo driver which wraps the existing shared libraries to connect to an ASE.

Please don’t hesitate to raise issue at and

You will find similar examples like the one of this blog post in the documentation of the above repositories.

Let’s go

The programming language Go by Google is getting more and more popular. Young talents learn the language and want to leverage powerful features like its concurrency model.

Within SAP IT we also love Go and want to use it for database tools around HANA and ASE. Up to now there was no SQL package driver available for ASE.

The new package go-ase is meant to fill this gap. So far it uses cgo to connect to the database using the shared libraries. However, a pure Go driver is planned.

Let’s go through a small example how you can use the package to write your own Go program.


To keep our example simple, we are going to use a SLES Linux server with a running ASE for Business Suite. To be able to compile a Go program you must have Go installed. Let’s install the latest version 1.12.5 released on May 5th.

# as root
tar -C /usr/local -xzf go1.12.5.linux-amd64.tar.gz

As the package uses cgo we also need gcc in place.

zypper in gcc

Write the Program

For simplicity we write our program as the ASE for Business Suite user syb<sid>. For this create a new directory with a file main.go.

# as syb<sid>
setenv PATH "$PATH":/usr/local/go/bin
mkdir myGoProgram
cd myGoProgram
vi main.go

Fill the file main.go with the following Go code and save it.

package main

import (

        _ ""

func main() {
        var login string
        flag.StringVar(&login, "login", "sa", "login you want to examine")

        dsn := libdsn.NewDsnInfoFromEnv("")
        db, err := sql.Open("ase", dsn.AsSimple())
        if err != nil {
                fmt.Fprintf(os.Stderr, "Could not open database: %v", err)
        defer db.Close()

        err = db.Ping()
        if err != nil {
                fmt.Fprintf(os.Stderr, "Could not ping database: %v", err)

        rows, err := db.Query("select dbname from master..syslogins where name = '?'", login)
        if err != nil {
                fmt.Fprintf(os.Stderr, "Could not query database: %v", err)
        defer rows.Close()

        var dbname string
        for rows.Next() {
                err := rows.Scan(&dbname)
                if err != nil {
                        fmt.Fprintf(os.Stderr, "Could not scan rows: %v", err)
                fmt.Printf("Database of %s is %s.\n", login, dbname)
        err = rows.Err()
        if err != nil {
                fmt.Fprintf(os.Stderr, "%v\n", err)

Also, let’s make it a Go module.

go mod init myGoProgram
go mod tidy

This downloads all the necessary dependencies to ~/go and creates a go.mod and a go.sum for you.

Compile the Program

Now compile the program.

setenv CGO_LDFLAGS "-L$SYBASE/OCS-16_0/lib -lsybct_r64 -lsybcs_r64"
go build

If the above fails, then please check if $SYBASE/OCS-16_0/lib has to be adjusted in your case.

Run the Program

As the program connects to your database you have to provide connections details. The above program uses environment variables.

setenv ASE_HOST '<host>'
setenv ASE_PORT 4901
setenv ASE_USER sapsa
setenv ASE_PASS '<pass>'

Then run your program:

Database of sa is master.

This prints the database of login sa. You can also specify different logins:

./myGoProgram -login sapsso
Database of sapsso is master.
./myGoProgram -login sapsa
Database of sapsa is saptools.

You can also specify an aseuserstore:


Again, run your program:

Database of sa is master.

What’s next?

You can use go-ase with your own Go programs to connect to and work with ASE databases. Next to the existing cgo package a pure Go implementation is planned. Please visit for more details about go-ase.


Many thanks to Nelo-T. Wallus for making this possible.


You must be Logged on to comment or reply to a post.