Connect to Oracle Database - C#

Connect to Oracle Database - C#

code snippet

c#
using Oracle.DataAccess.Client;
private void ConnectOracle()
{
    string strHost = "Host";
    string strPort = "1521";
    string strSID = "Database Name";
    string strUserID = "Username";
    string strPassword = "Password";
    string strConnectionString = string.Format("Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVER=DEDICATED)(SID={2})));Password={3};User ID={4}", strHost, strPort, strSID, strPassword, strUserID);
    using (OracleConnection con = new OracleConnection(strConnectionString))
    {
        con.Open();
        OracleCommand command = new OracleCommand("Select * from TABLE", con);
        // int result = command.ExecuteNonQuery();
        using (OracleDataReader reader = command.ExecuteReader())
        {
            if (reader.Read())
            {
                // read data from reader["FIELDNAME"]
            }
        }
        con.Close();
    }
}

"Thinking: the talking of the soul with itself"

Contact me!

Have questions? Feel free to use the form or send me an email with any questions.

I will be responsive to your requests and your questions.