1、首先建立一个工程,可选择控制台窗口模式

2、“引用”增加“Oracle.DataAccess.dll”组件,这组件一般在数据库的bin文件中

3、在main函数里添加,本身生成的为黑色,输入的用红色表示。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Oracle.DataAccess.Client;

namespace dbtest2
{
    class Program
    {
        static void Main(string[] args)
        {
              string CONN_STR = "Data Source=(DESCRIPTION="
                + "(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.128.152)(PORT=1521)))"
                + "(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=LYNN)));"
                + "User Id=fangl;Password=fangl;";

              if (string.IsNullOrEmpty(CONN_STR))//指示指定的字符串是 null 还是 Empty 字符串。
              {
                  throw new Exception("数据库访问服务出现故障,请联系晨旭公司!");
              }
              else
              {
                  OracleConnection conn = null;
                  try
                  {
                      conn = new OracleConnection(CONN_STR);
                      conn.Open();
                  }
                  catch (Exception e)
                  {
                      Console.WriteLine("{0}second exception caught",e);
                      Console.ReadLine();
                  }
                  Console.WriteLine("连接成功");
                  Console.ReadLine();
                  if (null != conn)
                  {
                      conn.Close();
                      conn.Dispose();
                  }
              }

        }
    }
}
4、运行,即可