Some drivers require environment variables setting before you can successfully connect (e.g. DB2 and DB2INSTANCE, Oracle and ORACLE_HOME). If you are using the unixODBC Driver Manager you can set environment variables per DSN in the odbc.ini file using the following syntax:
DMEnvAttr = SQL_ATTR_UNIXODBC_ENVATTR={ENVVAR=value}
e.g.
DMEnvAttr = SQL_ATTR_UNIXODBC_ENVATTR={DB2INSTANCE=db2inst2}
The unixODBC driver manager will then set the environment variable before connecting to the driver. Note, this only works this way when using DSN based connections.