Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


If this is properly set, the user can check the newly added ODBC items as follows.

ODBC Driver Development Guide


When connecting to the Altibase DB server with ODBC driver, separate source conversion is not required, and ODBC connection strings need to be changed in the connection part.

Compile and use appropriate heads (ex. windows.h, sql.h, sqlext.h, afxdb.h) and library (ex. odbc32.lib) that can integrate ODBC drivers required in WINDOWS.

ODBC connection string


In a program using the ODBC Driver, the connection string is used as follows.

The path marked in red is used as a keyword, and the part marked in blue can be used after changing the value according to the connection information of the Altibase DB Server to be connected and the ODBC version.

DRIVER=ALTIBASE_HDB_ODBC_64bit;user=sys;password=manager; Server=;PORT=20300;NLS_USE=MS949;LongDataCompat=on
DriverAltibase Driver name checked in ODBC management tool
UserUser account on DB
PasswordDB account password
ServerIP information where Altibase DB Server is located.
PortAltibase DB Server connection port information
NLS_USEDB character set
LongDataCompatON / OFF (Set to ON when using large data such as BLOB)

Visual C++ example source


A simple connection example in Visual C++ is as follows.

Code Block
titleVisual C++ example source
#include <Afx.h>
#include <Afxdb.h>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
    CDatabase db;
        db.OpenEx(_T("ODBC connection string”), CDatabase::noOdbcDialog);
        AfxMessageBox (_T("Connect OK"));
    }catch (CDBException *e)
    return 0;

Visual C# example source


A simple connection example in Visual C++ is as follows.

Code Block
titleVisual C# example source
using System;using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Odbc;
namespace ConsoleApplication1
    class Program
        static void Main(string[] args)
            OdbcConnection cn = new OdbcConnection();
                cn.ConnectionString = “ODBC connection string”;
                Console.WriteLine("connect ok");
            catch (OdbcException ex)

Visual Basic example source


A simple connection example in Visual Basic is as follows. In the example below, it is implemented as a source that connects to a DB and gets the current date and time. (The same applies when using ADO objects).

Code Block
titleVisual Basic example source
Sub Main() 
    Dim cn As Odbc.OdbcConnection
    Dim cmd As Odbc.OdbcCommand
    Dim dr As Odbc.OdbcDataReader
    cn = New Odbc.OdbcConnection
    cmd = New Odbc.OdbcCommand
    cn.ConnectionString = “ODBC connection string”
        Console.WriteLine("Successfully connected.")
        cmd.Connection = cn
        dr = cmd.ExecuteReader()
        While (dr.Read())
        End While
    Catch ex As Odbc.OdbcException
        Console.WriteLine("Error in the connection" + ex.Message)
    End Try
End Sub

Considerations when using LOB


In the case of Altibase, if LOB data type is used, it can be used after changing the connection information to Non-AutoCommit.

If not, NULL for LOB data type is brought when retrieving, or the following error occurs when insert/update time.

Code Block
Connection is in autocommit mode. One can not operate on LOB datas with autocommit mode on. 

With the following example of C# source, the user can see the process of inserting/selecting a BLOB data type into a table.

The example of BLOB insert is an example of changing the connection information to Non-AutoCommit and inserting data as described above while the DB is connected.

The used “blob” variable is declared as Byte[] type.

The example of BLOB select is an example that declares a Byte[] variable through a function called BINARY_LENGTH provided by Altibase to find out the length of a BLOB data type, saves data in the variable, and creates a file.

Code Block
titleExample of BLOB insert
// BLOB INSERTFileStream fs = new FileStream("c:\\test.dat", FileMode.Open, FileAccess.Read);
Byte[] blob = new byte[fs.Length];
fs.Read(blob, 0, System.Convert.ToInt32(fs.Length));
OdbcTransaction tx = cn.BeginTransaction();
cmd.Transaction = tx;
cmd.CommandText = "INSERT INTO T1 (C1, C2) VALUES (?, ?)";
cmd.Parameters.Add("C1", OdbcType.Int);
cmd.Parameters.Add("C2", OdbcType.Binary);
cmd.Parameters[0].Value = 1;
cmd.Parameters[1].Value = blob;
Code Block
titleExample of BLOB select
// BLOB SELECTcmd.CommandText = "SELECT binary_length(C2), C2 FROM T1";
tx = cn.BeginTransaction();
cmd.Transaction = tx;
OdbcDataReader dr = cmd.ExecuteReader();
int len;
while (dr.Read())
    len = dr.GetInt32(0);
    Byte[] ff = new Byte[len];
    dr.GetBytes(1, 0, ff, 0, len);
    fs = new FileStream("c:\\test.dat", FileMode.CreateNew, FileAccess.Write);
    fs.Write(ff, 0, len);