How to connect with System.Data.OracleClient to oracle db with windows authentication? How to connect with System.Data.OracleClient to oracle db with windows authentication? oracle oracle

How to connect with System.Data.OracleClient to oracle db with windows authentication?


Your problem not in connection string, but in your Active Directory structure, and Oracle settings for ability to use LDAP DB of AD, whats why if you try your code on local DB, for example OracleXE, without using active directory you probably will be succeed, but at the same time on the distributed Oracle server you can get authorization error, so find a strong administrator which will setup your AD and Oracle proper.


SQL Developer has sometimes ununderstandable behavior. It's not reliable for this "OS authentication" feature.

You should remove id completely from the authentication string:

string.Format("Data Source={0}; Integrated Security=yes;", dbName);

Edit

The fact that it works only when your remove the NTS option could mean the expected service isn't running, or that NTS doesn't support OS authentication for all users, but only for SYS. Found here some explanation:

The NTS service is used in windows environments to make the Sys user authentication based on the o/s level authentication. So if you are not willing to supply the password of the Sys user each time, you should set this .

And here someone who uses something you could try in its sqlnet.ora:

SQLNET.AUTHENTICATION_SERVICES =(NONE, NTS)

It may also depend of your Oracle version; here it says NTS is not supported with Oracle 12c

Starting with Oracle Database 12c Release 1 (12.1), the NTS authentication adapter no longer supports the use of NTLM to authenticate Windows domain users. Thus the NTS cannot be used to authenticate users in old Windows NT domains or domains with old Windows NT domain controllers. However, local connections and Oracle Database services running as a Windows Local User continues to be authenticated using NTLM.


In short, it's the Windows native operating system authentication which is indicated by NTS.

Once NTS is specified, oracle client identifies the username as workgroup\username or domain\username which does not match your OP$MYWINDOWSUSERNAME database user

In order to have it working with NTS option, you need to include domain/workgroup name in your db username:

CREATE USER "OPS$<DOMAIN_NAME>\<OS_USERNAME>" IDENTIFIED EXTERNALLY;

oracle support document 750436.1 confirms this with detailed steps.