How to connect to ORACLE DB without oracle client or tnsname

jen123 picture jen123 · Nov 4, 2015 · Viewed 8.1k times · Source

Is there any way to connect to Oracle DB without installing oracle client or using tnsname ? The application needs to be deployed on client machine ,hence want it to be INDEPENDENT.

Answer

Hambone picture Hambone · Nov 4, 2015

To clarify on my comment, this is possible with the Managed ODP.net from Oracle, which does not require the client machine to have any Oracle clients/drivers installed. It's perfect for Windows or console applications where you can't control the software that's installed on the target machines.

To download the managed client, you can get it from nuget using the Library Package Manager (https://www.nuget.org/packages/odp.net.managed/):

PM> Install-Package odp.net.managed

With regards to TNSnames (since that is also a client dependency), if you use Oracle's EZ Connect, you can bypass TNSnames completely. To do this, you simply format your data source as server-name:port/sid. I actually stopped using TNSnames completely ever since this became available.

Here is an example of how you can do this with Managed ODP.net:

OracleConnectionStringBuilder sb = new OracleConnectionStringBuilder();
sb.DataSource = "MyOracle.MyCompany.com:1521/MySid"; // EZ Connect -- no TNS Names!
sb.UserID = "luke";
sb.Password = "Jedi4Eva";

OracleConnection conn = new OracleConnection(sb.ToString());
conn.Open();

OracleCommand cmd = new OracleCommand("select * from dual", conn);
object o = cmd.ExecuteScalar();

conn.Close();