数据库连接Singleton模式 源码

 1/// <summary>
 2    /// 单件模式
 3    /// </summary>

 4    internal class Singleton
 5    {
 6        public static DataOracle instance = null;
 7        public Singleton( )
 8        {
 9            //
10            // TODO: 在此处添加构造函数逻辑
11            //
12        }

13        public static DataOracle Instance(string connString)
14        {
15            try
16            {
17                if(instance == null)
18                {
19                    instance = new DataOracle(connString);
20                }

21                return instance;
22            }

23            catch(Exception ex)
24            {
25                Log.WriteDataBase(DateTime.Now,"3",FrmMain.userName,ex.Message,"主机名:"+System.Net.Dns.GetHostName()+";IP地址:"+FrmMain.addressList[0]);
26                return new DataOracle();
27            }

28        }

29    }
posted @ 2008-06-27 11:03  jinweida  阅读(225)  评论(0编辑  收藏  举报