C# – Can’t connect to Oracle using Windows Authentication with ODP.NET

ado.netcdatabase connectionodp.netoracle

I've configured my Oracle Database for NTS Authentication and set my Windows Login up as a user in the database.

I'm able to log in to the Database with the command sqlplus /.

I'm also able to connect using Windows Authentication using the System.Data.OracleClient provider for ADO.NET.

For example, the following code snippet works:

DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.OracleClient");
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = "Data Source=//localhost/Test; Integrated Security=yes";
connection.Open();

However, I'm unable to connect using Windows Authentication using Oracle.DataAccess.Client (ODP.NET).

DbProviderFactory factory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
DbConnection connection = factory.CreateConnection();
connection.ConnectionString = "Data Source=//localhost/Test; User Id=/";
connection.Open();

This block of code results in the following exception:

Oracle.DataAccess.Client.OracleException was unhandled
Message=ORA-1017: invalid username/password; logon denied

According to this link I should be able to create an ODP.NET connection to Oracle using the provided connection string: http://www.oracle.com/technetwork/articles/dotnet/cook-masteringdotnet-090821.html

Why does the ODP.NET client not allow me to connect while the (deprecated) Microsoft client does?

This problem was discussed at the following thread in 2007, but no solution was every provided: http://forums.oracle.com/forums/thread.jspa?messageID=2312148.

This is a showstopper.

Best Answer

It works fine for me using ODP.net 11 and this connection string (with a tnsnames.ora file in the Oracle client to define DLGP): Data Source=DLGP;User Id=/;Password=;

Your sqnet.ora file needs to be setup correctly for this to work, but that should already be the case if SQLPlus can connect. Do you only have one Oracle home? If ODP.net is picking up a second one that can muck things up nicely (and that can happen depending on how you install it).

Related Topic