Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unixODBC/Oracle: How do I specify all the datasource info in the connection string ONLY, and not in the odbc*.ini files

I want to connect to Oracle (11g) using unixODBC. I want the connection string ONLY to specify all the database/data-source information, and the ODBC INI files (/etc/odbc.ini and /etc/odbcinst.ini) to contain only generic driver info like where to find the '.so' etc. i.e. I want them to be static. I want to do this so that I can get the connection string from the user externally, and connect to the datasource without having to modify any of the INI files or anything other on-disk configuration.

All the examples I saw make me define the server information in /etc/odbc.ini like this:

[myDSNname]
Driver = OracleODBC-11g
DSN = OracleODBC-11g
ServerName = //xxx.xxx.xxx.xxx:1521/SID_NAME
UserID = my_user
Password = my_pass

Now, I figured out how to get the UserID and Password out into the connection string by adding "UID=my_user;PWD=my_pass" to the connection string, and I removed them from odbc.ini. My joy quickly passed when I couldn't find the way to get ServerName out of odbc.ini and into the connection string as well. So how do I do this? And is there a way to get rid of the DSN in odbc.ini altogether, and have just the Driver from odbcinst.ini in the connection string, like we are doing for MySQL?

Edit: Trying any of the connection strings from www.connectionstrings.com that don't seem to require TNS or a DSN, incliuding EZCONNECT variants, all give me:

[HY000] [unixODBC][Oracle][ODBC][Ora]ORA-12162: TNS:net service name is incorrectly specified
    (12162) (SQLDriverConnectW)
like image 888
e.dan Avatar asked Jun 19 '12 09:06

e.dan


People also ask

How do I test Microsoft ODBC for Oracle connection?

Start the ODBC test utility by selecting Start > Programs > Oracle > Network Administration > Oracle ODBC Test or by searching your system for the file ODBCTST. EXE and double clicking on the file. Click on the CONNECT button displayed by the ODBC Test utility.


1 Answers

just use Dbq=address:1521/orcl ,and you will get what you want

like image 137
jack Avatar answered Oct 28 '22 17:10

jack