How can I connect to an Oracle Database from C# on Windows 7 x64 in my development environment
Asked Answered
A

2

12

I'm having difficulty connecting to an Oracle database on Windows 7x64

My environment is as follows:

  • Windows 7x64
  • Visual Studio 2012
  • Oracle 10g (with a 32 bit client)
  • WinForms

I've made the target CPU of all projects explicitly an x86 CPU (as opposed to Any or x86)

I'm connecting using DbProviderFactory.GetFactory

My ConnectionString entry in my app.config looks like this:

<add name="MYORACLE"
connectionString = "User ID=MYPASSWORD;Password=MYPASSWORd;Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=MYHOST)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=MYSERVICE)));"
providerName="System.Data.OracleClient" />

(I've tried it with various styles connection strings with no success)

When I compile the application, it is able to connect fine if I run the executable from the Debug folder. However, if I try to run it within Visual Studio it fails when I open the connection

ORA-06413: Connection not open.\n

Here's an example of how it's being called:

[TestMethod]
public void ConnectToOracle_Success()
{
    var connectionStringSettings = ConnectionBuilder.GetConnectionStringSetting(OracleConnectionName);
    var providerFactory = ConnectionBuilder.GetProviderFactory(connectionStringSettings);
    ConnectionBuilder.ValidateConnectionString(connectionStringSettings);
    using (var connection = providerFactory.CreateConnection())
    {
        Assert.IsNotNull(connection);
        connection.ConnectionString = connectionStringSettings.ConnectionString;
        try
        {
             connection.Open();
        }
        catch (Exception e)
        {
            Assert.Equals(e.Message, "");
        }
    }
}

I've seen something similar with Visual Basic 6 on Windows 7x64, and Oracle not liking the paths where it's installed (i.e., the parenthesis "Programs (x86)"). Is this the same sort of thing, or is there another way to convince Oracle to behave.

Arnst answered 24/12, 2013 at 17:52 Comment(11)
Is that ORA-06413 error what you get when you reach the connection.Open() line in the code snippet?Enravish
Yes looks like do you have Programs (x86) anywhere in the connectionstring?Ariose
Console app? Win forms?Conceptacle
The problem is with (x86) paranthesis. Try to re-install the application outside the Programs(x86) folder.Sinter
ORA-06413 seems to be what I get when the Open() line is reachedArnst
Part of it is there isn't an (x86) in the path to VS2012 or the solution's files. So I'm not sure what other piece might have that in its path, or if that really is the cause.Arnst
Probably off-topic, but have you tried running VS2012 as Administrator?Arthro
typo in your question - you've made it an x86 CPU target, not x64 right?Arthro
Correct, there was a typo. I'm building on x86 (32bit) on an a 64 bit box.Arnst
@Arthro - I'm already a member of the Administrators group on the workstation.Arnst
Ok, but launching VS2012 as Administrator (right click on the shortcut > run as admin) makes a difference to some things like registry access, as the process then has an elevated security token. Worth trying although I'm guessing that's not it.Arthro
E
2

Oh, the dreaded parenthesis in Oracle provider. The simplest way around it is to use a newer version of the client where the issue was fixed. With Oracle 10g database you can safely use up to 12.1.x client (available here: 64-bit Oracle Data Access Components).

With 64-bit os there's another trick I used: firstly install 32-bit version of the client, and on top of it install 64-bit version. That way some apps like Office or old VS dev web server will still work.

Espagnole answered 9/1, 2014 at 12:33 Comment(0)
M
5

This could be a OCI client version issue. See https://community.oracle.com/message/11103466.

I have seen a lot of issues with this. Most of the time this has to do with a ODP.NET assembly (such as Oracle.DataAccess) which is in a different version then the operating system architecture (we are talking bits here).

There are a few things you could do about this:

  1. Install both 32- and 64-bit ODP.NET client tools (including OCI for that architecture), free to download from oracle.com.

  2. Build your application for a specific processor architecture, such as 32-bit.

  3. Use a third party Oracle client connector that is not dependent on OCI (this is what gives the problems). I wouldn't recommend this, since this is most of the time the expensive solution.

Minneapolis answered 4/1, 2014 at 15:6 Comment(1)
Patrick - Sorry, I missed your answer I'm working through it right now.Arnst
E
2

Oh, the dreaded parenthesis in Oracle provider. The simplest way around it is to use a newer version of the client where the issue was fixed. With Oracle 10g database you can safely use up to 12.1.x client (available here: 64-bit Oracle Data Access Components).

With 64-bit os there's another trick I used: firstly install 32-bit version of the client, and on top of it install 64-bit version. That way some apps like Office or old VS dev web server will still work.

Espagnole answered 9/1, 2014 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.