Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to ORACLE DB without oracle client or tnsname

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.

like image 273
jen123 Avatar asked Nov 04 '15 10:11

jen123


People also ask

Can I connect to Oracle without Tnsnames?

The easy way to connect to oracle without tnsnames. ora is using EZCONNECT or you can say Oracl' easy connect naming method. We can connect to oracle database across TCP/IP network. We can connect to oracle using connect descriptor or connection string you can say that as connect identifier.


1 Answers

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();
like image 200
Hambone Avatar answered Oct 19 '22 12:10

Hambone