This discussion is archived
3 Replies Latest reply: Nov 16, 2012 9:07 AM by Mark Williams-Oracle RSS

Connection string format to connect to Oracle DB through LDAP

863906 Newbie
Currently Being Moderated
Hi,

I have an Oracle database and its details are configured in LDAP. I have C# code from which I want to connect to Oracle DB using LDAP details. So i have written code to connect to the Oracle DB, but not able to connect. Getting error at con.Open() statement : "ORA-12154: TNS:could not resolve the connect identifier specified".

Code:
--------
string constr = "Data Source=@ldap://abc.pq.xyz.com:11389/myldap,cn=OracleContext,dc=pq,dc=xyz,dc=com;User Id=MyDB;Password=MyPass";

OracleConnection con = new OracleConnection(constr);
con.Open();

I need help in forming the connection string.
  • 1. Re: Connection string format to connect to Oracle DB through LDAP
    Mark Williams-Oracle Employee ACE
    Currently Being Moderated
    user8786648 wrote:
    Hi,

    I have an Oracle database and its details are configured in LDAP. I have C# code from which I want to connect to Oracle DB using LDAP details. So i have written code to connect to the Oracle DB, but not able to connect. Getting error at con.Open() statement : "ORA-12154: TNS:could not resolve the connect identifier specified".

    Code:
    --------
    string constr = "Data Source=@ldap://xyz.us.oracle.com:11389/xyz_ldap,cn=OracleContext,dc=us,dc=oracle,dc=com;User Id=xyz;Password=xyz";

    OracleConnection con = new OracleConnection(constr);
    con.Open();

    I need help in forming the connection string.
    That's not how you use LDAP for Oracle name resolution.

    You need to configure the LDAP.ORA and SQLNET.ORA files appropriately.

    For example, you can review the LDAP.ORA documentation here:

    http://docs.oracle.com/cd/E11882_01/network.112/e10835/ldap.htm#i500397

    And the SQLNET.ORA documentation here:

    http://docs.oracle.com/cd/E11882_01/network.112/e10835/sqlnet.htm#i500318

    A quick web search on the terms "oracle ldap.ora example" turned up several examples.

    Also, if those are actual values you posted in your sample connect string, you may want to edit.
  • 2. Re: Connection string format to connect to Oracle DB through LDAP
    863906 Newbie
    Currently Being Moderated
    I am able to connect to the database using the connection string as follows after creating the ldap.ora and sqlnet.ora files in respective folders.
    string constr = "Data Source=myldap;User Id=MyDB;Password=MyPass";
    where myldap in LDAP entry pointing to database.

    Here I have still some more questions related to this topic
    1. Is Oracle Client required to use ODP.NET(need to be there in client machine from where we run C# code using ODP.NET). Or if i just create ldap.ora and sqlnet.ora files in required paths is enough.
    2. Do I need to create the files ldap.ora and sqlnet.ora manually or need to get them from OID and DB servers. Or eigher way is ok.
    3. My Oracle DB server not contains any ldap.ora file at /vol1/oracle/product/11R1/ldap/admin/, will this be there at OID server or its not required in DB Server machine.(My Db Machine is configured by some others, I don't know actual details)
    4. I am seeing the contents of DB Servers sqlnet.ora file as below, is this ok, there is no LDAP entry in Directory Path:
    # sqlnet.ora Network Configuration File: /vol1/oracle/product/11R1/network/admin/sqlnet.ora
    # Generated by Oracle configuration tools.

    NAMES.DIRECTORY_PATH= (TNSNAMES)
  • 3. Re: Connection string format to connect to Oracle DB through LDAP
    Mark Williams-Oracle Employee ACE
    Currently Being Moderated
    1. Is Oracle Client required to use ODP.NET(need to be there in client machine from where we run C# code using ODP.NET). Or if i just create ldap.ora and sqlnet.ora files in required paths is enough.

    Yes, an Oracle Client is required. Though there is currently a beta release for a fully managed version of ODP.

    2. Do I need to create the files ldap.ora and sqlnet.ora manually or need to get them from OID and DB servers. Or eigher way is ok.

    The documentation recommends using the Net Manager and the Net Configuration Assistant for configuring these files; however, they are just text files. You can create using the tools or manually or copy known correct versions if available.

    3. My Oracle DB server not contains any ldap.ora file at /vol1/oracle/product/11R1/ldap/admin/, will this be there at OID server or its not required in DB Server machine.(My Db Machine is configured by some others, I don't know actual details)

    You want to use this configuration from a client. So if the db server is not itself acting as a client then they would not be required on the db server.

    4. I am seeing the contents of DB Servers sqlnet.ora file as below, is this ok, there is no LDAP entry in Directory Path:
    # sqlnet.ora Network Configuration File: /vol1/oracle/product/11R1/network/admin/sqlnet.ora
    # Generated by Oracle configuration tools.

    NAMES.DIRECTORY_PATH= (TNSNAMES)

    See response to #3 above. That is typical for a server-side copy of the file.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points