Data Access Tracing with the ODBC Driver on Linux and macOS

DownloadDownload ODBC Driver

The unixODBC Driver Manager on macOS and Linux supports tracing of ODBC API call entry and exit of the ODBC Driver for SQL Server.

To trace your application's ODBC behavior, edit the odbcinst.ini file's [ODBC] section to set the values Trace=Yes and TraceFile to the path of the file which is to contain the trace output; for example:


(You may also use /dev/stdout or any other device name to send trace output there instead of to a persistent file.) With the above settings, every time an application loads the unixODBC Driver Manager, it will record all the ODBC API calls which it performed into the output file.

After you finish tracing your application, remove Trace=Yes from the odbcinst.ini file to avoid the performance penalty of tracing, and ensure any unnecessary trace files are removed.

Tracing applies to all applications that use the driver in odbcinst.ini. To not trace all applications (for example, to avoid disclosing sensitive per-user information), you can trace an individual application instance by providing it the location of a private odbcinst.ini, using the ODBCSYSINI environment variable. For example:

$ ODBCSYSINI=/home/myappuser myapp

In this case, you can add Trace=Yes to the [ODBC Driver 13 for SQL Server] section of /home/myappuser/odbcinst.ini.

Determining which odbc.ini File the Driver is Using

The Linux and macOS ODBC drivers do not know which odbc.ini is in use, or the path to the odbc.ini file. However, information about which odbc.ini file is in use is available from the unixODBC tools odbc_config and odbcinst, and from the unixODBC Driver Manager documentation.

For example, the following command prints (among other information) the location of system and user odbc.ini files which contain, respectively, system and user DSNs:

$ odbcinst -j
unixODBC 2.3.1
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
USER DATA SOURCES..: /home/odbcuser/.odbc.ini`
SQLULEN Size.......: 8
SQLLEN Size........: 8

The unixODBC documentation explains the differences between user and system DSNs. In summary:

  • User DSNs --- these are DSNs which are only available to a specific user. Users can connect using, add, modify, and remove their own user DSNs. User DSNs are stored in a file in the user's home directory, or a subdirectory thereof.

  • System DSNs --- these DSNs are available for every user on the system to connect using them, but can only be added, modified, and removed by a system administrator. If a user has a user DSN with the same name as a system DSN, the user DSN will be used upon connections by that user.

See Also