OracleCredential Class
OracleCredential
class provides a secure way to provide password while opening connection with Oracle Database using the ODP.NET driver. Use this class to avoid providing passwords in clear text in the connection string while opening a connection with Oracle Database. One can pass user id, password and DBA Privilege specific attributes through OracleCredential
constructors and thus these attributes do not need to be in the connection string.
Operating system authenticated and context connections are not supported through OracleCredential
class. An ArgumentException
will be thrown if "/
" is passed for userId
or proxyUserId
arguments of OracleCredential
constructor.
Class Inheritance
System.Object
Oracle.DataAccess.Client.OracleCredential
Declaration
// C# public sealed class OracleCredential
Requirements
Provider | ODP.NET, Unmanaged Driver | ODP.NET, Managed Driver | ODP.NET Core |
---|---|---|---|
Assembly |
|
|
|
Namespace |
|
|
|
.NET Framework |
4.8 |
4.8 |
- |
.NET (Core) |
- |
- |
Thread Safety
All public static methods are thread-safe, although instance methods do not guarantee thread safety.
Example
// C# using System; using System.Data; using System.Security; using Oracle.DataAccess.Client; //using Oracle.ManagedDataAccess.Client; class OracleCredentialSample { static void Main() { // Connect string constr = "Data Source=oracle"; SecureString secPwd = new SecureString(); secPwd.AppendChar('h'); secPwd.AppendChar('r'); // Make the password read-only. secPwd.MakeReadOnly(); // Create OracleCredential with userid and secure password. OracleCredential oc = new OracleCredential("hr", secPwd); OracleConnection con = new OracleConnection(constr, oc); con.Open(); // Execute a SQL SELECT OracleCommand cmd = con.CreateCommand(); cmd.CommandText = "select * from employees"; OracleDataReader reader = cmd.ExecuteReader(); // Print all employee numbers while (reader.Read()) Console.WriteLine(reader.GetInt32(0)); // Clean up reader.Dispose(); cmd.Dispose(); con.Dispose(); } }