Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am able to create an OLEDb connection. However, I am not able to retrieve data. I ran the same query in using 'SQL Developer' and it had data.

Please advise.

Thank you.

What I have tried:

I am able to create an OLEDb connection with the following codes:
C#
      var cfg = ConfigurationManager.AppSettings;

      string dirSvr = cfg["ldapServer"];
      string context = cfg["ldapContext"];
      string svcname = cfg["ldapSvcName"];

      string ldapAdress = $"LDAP://{dirSvr}/{context}";
      string query = $"(&(objectclass=orclNetService)(cn={svcname}))";
      string orclnetdescstring = "orclnetdescstring";

        DirectoryEntry directoryEntry = new DirectoryEntry(ldapAdress, null, null, AuthenticationTypes.Anonymous);
        DirectorySearcher directorySearcher = new DirectorySearcher(directoryEntry, query, new[] { orclnetdescstring }, SearchScope.Subtree);

        SearchResult searchResult = directorySearcher.FindOne();
        byte[] value = searchResult.Properties[orclnetdescstring][0] as byte[];

        string descriptor = "";
        if (value != null)
        {
          descriptor = Encoding.Default.GetString(value);
        }
        else throw new Exception("LDAP response was empty");

        string s = "Min Pool Size=1;Max Pool Size=10;Provider=OraOLEDB.Oracle;Pooling=true;User ID=usr;Password=pwd"; Data Source=" + descriptor + ";";
        OleDbConnection con = new OleDbConnection(s);

string strSQL = "Select * from users";

      con.Open(); //success
      OleDbDataAdapter oDA = new OleDbDataAdapter(strSQL, con);
      DataSet ds = new DataSet();
      oDA.Fill(ds);
      con.Close();
Posted
Updated 22-Dec-22 19:15pm
v2
Comments
PIEBALDconsult 22-Dec-22 14:40pm    
You appear to have some issues with delimiting some strings.

1 solution

string s = "Min Pool Size=1;Max Pool Size=10;Provider=OraOLEDB.Oracle;Pooling=true;User ID=usr;Password=pwd"; Data Source=" + descriptor + ";";
Your string formation looks incorrect.

Try:
C#
string s = "Min Pool Size=1;Max Pool Size=10;Provider=OraOLEDB.Oracle;Pooling=true;User ID=usr;Password=pwd;Data Source=" + descriptor + ";";

Make use of debugger and see your connection string is correctly formed (as anticipated).
 
Share this answer
 
Comments
George Swan 24-Dec-22 7:06am    
That looks better. I would not add the semicolon to the end of the string.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900