Skip to content

Instantly share code, notes, and snippets.

@thenasim
Last active December 2, 2021 13:16
Show Gist options
  • Save thenasim/167f5785d8c40d1f8469fabeb36c6b76 to your computer and use it in GitHub Desktop.
Save thenasim/167f5785d8c40d1f8469fabeb36c6b76 to your computer and use it in GitHub Desktop.
using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OracleConn
{
public class OracleDbAccess
{
private const string ConnectionString = @"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=orcl)));User ID=system;Password=1234;";
private static OracleConnection _con;
public static OracleConnection Connection
{
get
{
if (_con == null)
{
_con = new OracleConnection(ConnectionString);
}
if (_con != null && _con.State == ConnectionState.Closed)
{
_con.Open();
}
return _con;
}
}
public static OracleDataReader GetData(string command)
{
OracleCommand cmd = new OracleCommand(command, Connection);
OracleDataReader reader = cmd.ExecuteReader();
return reader;
}
public static int UpdateDeleteInsert(string command)
{
OracleCommand cmd = new OracleCommand(command, Connection);
return cmd.ExecuteNonQuery();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment