I have been reading about how to connect to my oracle database from my C# win application, but I keep “hitting the wall”. I have decided to use odp.net and OCI, such that the client computer not needs to install a client, but I can’t get it to work.
I have a small test application, the code I shown below and in my solution I have added the following dll’s from oracle OCI: oci.dll, orannzsbb11.dll and oraociicus11.dll. They are all placed together with the final .exe file.
Test Code:
private static string CONNECTION_STRING =
"User Id=hr;Password=hr;Data Source=(DESCRIPTION=" +
"(ADDRESS=(PROTOCOL=TCP)(HOST=127.0.0.1)(PORT=1521))" +
"(CONNECT_DATA=(SID=XE)));Connect Timeout=15;";
static void Main(string[] args)
{
try
{
using (var conn = new OracleConnection(CONNECTION_STRING))
{
conn.Open();
Console.WriteLine("Connection is: {0}", conn.State.ToString());
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
The problem occurs already in the using(…) statement, the program just stop working and I get no response. What is the magic that I need to do to get the OCI to work???