Document Type | Technical Information
Category | Utility
Applicable Product Version | 7FS02PS
Document Number | TUTTI025
Overview
By default, the ESQL program references the TB_SID environment variable and the Tibero Client's tbdsn.tbr file to connect to the database.
If two or more connection settings are specified in the tbdsn.tbr file, you can select the database you want to connect to by using the TB_SID environment variable.
The tbdsn.tbr file is a configuration file that contains the information needed for the client to connect to the database.
[tbdsn.tbr file]
#-------------------------------------------------
# /home/tibero/hooyoung/ps04/tibero7/client/config/tbdsn.tbr
# Network Configuration File.
# Generated by gen_tip.sh at Wed Nov 5 04:25:33 PM KST 2025
tibero7ps04=(
(INSTANCE=(HOST=localhost)
(PORT=1234)
(DB_NAME=tibero7ps04)
)
)
remote=(
(INSTANCE=(HOST=192.168.139.14)
(PORT=8629)
(DB_NAME=remote)
)
)
For the ESQL connection test, two database connection entries were entered in the tbdsn.tbr file, and the source code used was written to read the TB_SID environment variable set at runtime, allowing it to select the target database for connection.
Method
Test Details
1) Connecting to a local DB without a user
[tibero@localhost tibero7]$ echo $TB_SID
tibero7ps04
[tibero@localhost tibero7]$ tbsql sys/tibero
tbSQL 7
TmaxTibero Corporation Copyright (c) 2020-. All rights reserved.
Connected to Tibero.
SQL> drop user tibero;
User 'TIBERO' dropped.
SQL> q
Disconnected.
[tibero@localhost tbpc]$ ./test
Connection Fail ( SQLCODE : -17001 ) !!
=> Connection failed due to dropping the Tibero account.
- test: Connection test executable file (attempts to connect with the tibero account and returns an error, see source code below)
2) Normal remote DB connection test
[tibero@localhost tbpc]$ echo $TB_SID
remote
[tibero@localhost tbpc]$ ./test
Connected to Tibero as user tibero
[result] col3 : []
=> As in test 1), confirmed normal connection to the remote DB in tbdsn.tbr from the same server.
3) Setting the DB to connect to by changing the TB_SID setting
[tibero@localhost tbpc]$ TB_SID=tibero7ps04
[tibero@localhost tbpc]$ echo $TB_SID
tibero7ps04
[tibero@localhost tbpc]$ ./test
Connection Fail ( SQLCODE : -17001 ) !!
[tibero@localhost tbpc]$ TB_SID=remote
[tibero@localhost tbpc]$ echo $TB_SID
remote
[tibero@localhost tbpc]$ ./test
Connected to Tibero as user tibero
[result] col3 : []
As shown in the tests above, even if the executable file named test has already been created, you can connect to the desired database simply by changing the TB_SID environment variable.
Caution
1. Check if the firewall on the remote DB is disabled
- Connection failure
2) Check the include path in tbpc.cfg
- Error occurs when the header file cannot be found during precompile via tbpc
3) Check compile options per OS
- Unable to generate a valid executable file
4) Restore TB_SID
- Cannot connect to local DB when set to remote TB_SID
Appendix
1) test.tbc source
#include <stdio.h>
#include <sqlca.h>
#include <stdlib.h>
#include <string.h>
#define USERPASS "tibero/tmax"
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
VARCHAR userpass[20] = {strlen(USERPASS), USERPASS};
char col3_value[100];
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT :userpass;
memset(col3_value, 0x00, sizeof(col3_value));
if ( sqlca.sqlcode != 0 ) {
printf(" Connection Fail ( SQLCODE : %d ) !! \n\n", sqlca.sqlcode );
}
else {
printf(" Connected to Tibero as user tibero \n\n");
EXEC SQL
select col3
into :col3_value
from esql_tmp1
where col1 = 1;
printf("[result] col3 : [%s]\n", col3_value);
}
EXEC SQL COMMIT WORK RELEASE;
return 0;
}
2) How to compile
[Compile Example]
#!/bin/sh # program compile #main COMP_TARGET=$1; export COMP_TARGET make -f Makefile.tbc all
[Makefile.tbc Example]
# Server tb*C makefile
TBLIBDIR = $(TB_HOME)/client/lib
TBLIB = -ltbxa -ltbertl -ltbcli -lclialloc
TARGET = $(COMP_TARGET)
APOBJS = $(TARGET).o
OBJS = $(APOBJS)
CFLAGS = -g -I$(TB_HOME)/client/include
#
.SUFFIXES : .c
.c.o:
$(CC) $(CFLAGS) -c $<
#
# server compile
#
all: $(TARGET)
$(TARGET): $(OBJS)
$(CC) $(CFLAGS) -o $(TARGET) -L$(TBLIBDIR) $(TBLIB) $(OBJS)
rm -f $(OBJS)
$(APOBJS): $(TARGET).tbc
tbpc iname=$(TARGET) include=$(TB_HOME)/client/include
$(CC) $(CFLAGS) -c $(TARGET).c
clean:
-rm -f *.o core $(TARGET) $(TARGET).lis
[How to compile]
[tibero@localhost tbpc]$ ./compile test
tbpc iname=test include=/home/tibero/hooyoung/ps04/tibero7/client/include
tbESQL Precompiler 7
TmaxTibero Corporation Copyright (c) 2020-. All rights reserved.
test.tbc is precompiled successfully!
cc -g -I/home/tibero/hooyoung/ps04/tibero7/client/include -c test.c
cc -g -I/home/tibero/hooyoung/ps04/tibero7/client/include -o test -L/home/tibero/hooyoung/ps04/tibero7/client/lib -ltbxa -ltb
rm -f test.o
Confirmed executable file runs normally
[tibero@localhost tbpc]$ ./test
Connected to Tibero as user tibero
[result] col3 : []
3) tbpc.cfg
#------------------------------------------------------------------------------ # # /home/chef/workspace/Build_centos_8/tibero7/client/config/tbpc.cfg # # tbESQL Configuration file for Preprocessor # # Each command should be specified in a single line by itself terminated by # a newline. # Lines starting with a # character are comments which are ignored. # # Generated at Mon Oct 13 01:53:04 UTC 2025 # #------------------------------------------------------------------------------ INCLUDE=$TB_HOME/client/include INCLUDE=/usr/lib/gcc/x86_64-redhat-linux/11/include (need to set according to OS environment) INCLUDE=/usr/include