1
votes

I have simple c# application that conencts to Oracle 12c. User provides information about their Oracle server: host, port, service name, user name and password. On the machine where application is launched i have "fat" Oracle Native Client 12.02.00.01 installed together with my app. I need a connection string to connect to the server user provided. When i modify tnsnames.ora file of client to have tns service name specified:

somealias=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=somehost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCL))

i can use this connection string

DRIVER={Oracle in OraClient12Home2};Dbq=somealias;uid=someuser;pwd=somepassword;

and everything is working fine.

But, having user modify client tnsnames.ora file providing their connection information before launching app is not an option. Also modifying tnsnames.ora client file in runtime each time user enters some information in app is not an option either. Having users create Datasource before launching app or creating datasource in runtime each time some of the fields are edited is not an option. I must find a way how to specify driver host port sid/service name user name and password in connection string omitting tnsnames.ora file or datasource.

I tried several strings:

  1. DRIVER={Oracle in OraClient12Home2};SERVER=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=somehost)(PORT=1521)))(CONNECT_DATA=(SERVICE_NAME=ORCL));uid=someuser;pwd=somepassword;
  2. Driver={Oracle in OraClient12Home2};DataSource=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=somehost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));Uid=someuser;Pwd=somepassword;
  3. ODBC;Driver={Oracle in OraClient12Home2};SERVER=somehost:1521/ORCL;UID=someuser;PWD=somepassword;DBQ=somehost:1521/ORCL;
  4. Driver={Oracle in OraClient12Home2};Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=somehost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));User Id=someuser;Password=somepassword;
  5. Driver={Oracle in OraClient12Home2};Data Source=somehost:1521/ORCL;Persist Security Info=True;User ID=someuser;Password=somepassword;Unicode=True;

None of them worked. Here is my code (note that formatting is changing depending of which connection string will be used):

var driver = "{" + driverName + "}";
                var connect = "DRIVER=" + driver
                              + ";UID=" + UserName
                              + ";PWD=" + Password
                              + ";HOST=" + Host
                              + ";PORT=" + Port
                              + ";SERVICENAME=" + ServiceName; 
                var connection = new OdbcConnection(connect);
                connection.Open();

What i need is a connection string where i can specify:

  1. driver that is used
  2. host
  3. port
  4. sid or service name
  5. user name
  6. password

Driver im currently trying to use is SQORA32.dll delivered with Oracle native client 12.2.0.1

Any help is much appriciated

1
Instead of tnsnames.ora file you can provide alias resolution also by a name server (LDAP) However most likely that would be an overkill in your environment.Wernfried Domscheit

1 Answers

0
votes

Ok, i got the connection string that is working

Driver={Oracle in OraClient12Home2};DBQ=somehost:port/servicename;UID=someuser;PWD=somepassword;