I covered this topic a while ago in an older blogpost, but to keep it simple: It also works for Oracle!

privatestaticvoidOracleTest(){stringconstr="Data Source=localhost;User Id=...;Password=...;";DbProviderFactoryfactory=DbProviderFactories.GetFactory("Oracle.ManagedDataAccess.Client");using(DbConnectionconn=factory.CreateConnection()){try{conn.ConnectionString=constr;conn.Open();using(DbCommanddbcmd=conn.CreateCommand()){dbcmd.CommandType=CommandType.Text;dbcmd.CommandText="select name, address from contacts WHERE UPPER(name) Like UPPER('%' || :name || '%') ";vardbParam=dbcmd.CreateParameter();// prefix with : possible, but @ will be result in an errordbParam.ParameterName="name";dbParam.Value="foobar";dbcmd.Parameters.Add(dbParam);using(DbDataReaderdbrdr=dbcmd.ExecuteReader()){while(dbrdr.Read()){Console.WriteLine(dbrdr[0]);}}}}catch(Exceptionex){Console.WriteLine(ex.Message);Console.WriteLine(ex.StackTrace);}}}

MSSQL, MySql and Oracle - via DbProviderFactories

The above code is a snippet from my larger sample demo covering MSSQL, MySQL and Oracle. If you are interested just check this demo on GitHub.

Each SQL-Syntax teats parameter a bit different, so make sure you use the correct syntax for your target database.

Bottom line

Accessing a Oracle database from .NET doesn’t need to be a pain nowadays.

Be aware that the ODP.NET provider might surface higher level APIs to work with Oracle databases. The dbProviderfactory-approach helped us for our simple “just load some data”-scenario.