heisetoufa 发表于 2013-2-5 01:07:01

c# winform winform连接数据库的类

class OracleConnectPool   {    public static int NumOfConn = 10;    public static string conn_str="Data Source=eerp;user=LC_USER;password=LC_USER;";    public static OracleConnection[] Conns= new OracleConnection;    public static DateTime[] OpenTimes = new DateTime;    public static OracleConnection GetConnect()    {   try   {      int OldestConn = 0;      for(int i=0;i< NumOfConn ;i++)      {       if(Conns == null)       {      Conns = new OracleConnection(conn_str);      Conns.Open();      OpenTimes = DateTime.Now;      return Conns;       }       else if(Conns.State == System.Data.ConnectionState.Closed)       {      Conns.Open();      OpenTimes = DateTime.Now;      return Conns;       }       else if(Conns.State == System.Data.ConnectionState.Open)       {      if(OpenTimes < OpenTimes)         OldestConn = i;       }      }             OpenTimes = DateTime.Now;      return Conns;   }   catch   {      Exception myEX=new Exception("数据库连接失败,请重试!");      throw myEX;   }    }}  
黑色头发  http://heisetoufa.iteye.com
页: [1]
查看完整版本: c# winform winform连接数据库的类