C# .NET Programming Tip: Oracle Connection Revised

Take not that Microsoft will discontinue support for System.Data.OracleClient in .NET 4.0. This method should still work, but it will be depreciated…

Now that I have had more time to work with Oracle, I found a better way to connect then described in my previous post. With this new method you can connect to multiple instances in one program by getting rid of that tnsnames file.

*Remember that a project reference to System.Data.OracleClient must be added:

OracleConnection dbConnection;

string connectionString = "Server=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = *******)(PORT = 1521))(CONNECT_DATA = (SID = *****)));Persist Security Info=true;User Id=*****;Password=*****;";

dbConnection = new OracleConnection(connectionString);

It’s really that simple. The key here is that the connection string must use the “Server” attribute instead of the “Data Source” one. I ran upon that while looking at the specification on Microsoft’s MSDN documentation site.

It’s basically a tnsnames string with a few more attributes like user id and password. Just remember that:
host is the name of your server or ip address, sid is the name of your database meaning the *** part of ***.world, and of course the user id and password are your login credentials.

There is another helpful step that I will be posting about. It relates to ClickOnce and the 4 DLL files that you need to connect to Oracle.

Tags: , , , , , ,

2 Responses to “C# .NET Programming Tip: Oracle Connection Revised”

  1. Lore Says:

    I have my .exe (framework 2.0), the 4 DLLs you mention all in the same directory. I also am using System.Data.OracleClient. When I run the exe, I receive error “System.Data.OracleClient requires Oracle client software version 8.1.7 or greater.” So, my exe is not looking into the current directory for the dlls. Any ideas?

  2. Scott Says:

    Well, I’ve only distributed my apps through clickonce deployment, so I can’t really say what the issue is at this point.

    I’m just guessing here, but when visual studio is used to deploy the application, it includes a manifest file, which tells where and what is included in the application. So I’m not sure you can just copy the DLLS and the program executable into a directory without all of the support files as well. Also, when I include the oracle DLLs in the project itself, I tell it to copy the oracle files into the EXE directory (the application then knows they exist).




The Way Of Coding



 
Scott J. Waldron Photography
Stock Photo Website
Tech Learning Site
Follow me on Twitter

Popular Article Tags

Archives

Pages