using System;
using System.Data;
using Oracle.ManagedDataAccess.Client;
namespace ODP.NET
{
class Program
{
static void Main(string[] args)
{
OracleConnection conn = null;
try
{
conn = OpenConn();
var cmd = conn.CreateCommand();
cmd.CommandText = "select * from s_awb_master where rownum=1";
cmd.CommandType = CommandType.Text;
var reader = cmd.ExecuteReader();
while (reader.Read())
{
Console.WriteLine(string.Format("AwbPre:{0},AwbNo:{1}", reader["AwbPre"], reader["AwbNo"]));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
CloseConn(conn);
}
Console.Read();
}
static OracleConnection OpenConn()
{
OracleConnection conn = new OracleConnection();
conn.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=***.***.***.***)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=***)));Persist Security Info=True;User ID=***;Password=***;";
conn.Open();
return conn;
}
static void CloseConn(OracleConnection conn)
{
if (conn == null) { return; }
try
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
finally
{
conn.Dispose();
}
}
}
}