Esempio n. 1
0
        private IDataBase CreateForWeb()
        {
            String    key = ConnName + "_DB";
            IDataBase d;

            if (HttpContext.Current.Items[key] != null && HttpContext.Current.Items[key] is IDataBase)
            {
                d = HttpContext.Current.Items[key] as IDataBase;
            }
            else
            {
                if (DALType == typeof(Access))
                {
                    d = new Access(ConnStr);
                }
                else if (DALType == typeof(SqlServer))
                {
                    d = new SqlServer(ConnStr);
                }
                else if (DALType == typeof(MySql))
                {
                    d = new MySql(ConnStr);
                }
                else if (DALType == typeof(SQLite))
                {
                    d = new SQLite(ConnStr);
                }
                else
                {
                    d = DALType.Assembly.CreateInstance(DALType.FullName, false, BindingFlags.Default, null, new Object[] { ConnStr }, null, null) as IDataBase;
                }

                if (DataBase.Debug)
                {
                    DataBase.WriteLog("创建DB(Web):{0}", d.ID);
                }

                HttpContext.Current.Items.Add(key, d);
            }
            //检查是否SqlServer2005
            //_DB = CheckSql2005(_DB);

            if (!IsSql2005.ContainsKey(ConnName))
            {
                lock (IsSql2005)
                {
                    if (!IsSql2005.ContainsKey(ConnName))
                    {
                        IsSql2005.Add(ConnName, CheckSql2005(d));
                    }
                }
            }

            if (IsSql2005.ContainsKey(ConnName) && IsSql2005[ConnName])
            {
                _DALType = typeof(SqlServer2005);
                d.Dispose();
                d = new SqlServer2005(ConnStr);
            }

            d.SqlLog = EnableSqlLog;
            return(d);
        }
Esempio n. 2
0
        private IDataBase CreateForNotWeb()
        {
            if (_DBs == null)
            {
                _DBs = new Dictionary <String, IDataBase>();
            }
            if (_DBs.ContainsKey(ConnName))
            {
                return(_DBs[ConnName]);
            }
            lock (_DBs)
            {
                if (_DBs.ContainsKey(ConnName))
                {
                    return(_DBs[ConnName]);
                }

                // 创建对象,先取得程序集,再创建实例,是为了防止在本程序集创建外部DAL类的实例而出错

                IDataBase _DB;
                if (DALType == typeof(Access))
                {
                    _DB = new Access(ConnStr);
                }
                else if (DALType == typeof(SqlServer))
                {
                    _DB = new SqlServer(ConnStr);
                }
                else if (DALType == typeof(SqlServer2005))
                {
                    _DB = new SqlServer2005(ConnStr);
                }
                else if (DALType == typeof(MySql))
                {
                    _DB = new MySql(ConnStr);
                }
                else if (DALType == typeof(SQLite))
                {
                    _DB = new SQLite(ConnStr);
                }
                else
                {
                    _DB = DALType.Assembly.CreateInstance(DALType.FullName, false, BindingFlags.Default, null, new Object[] { ConnStr }, null, null) as IDataBase;
                }
                //检查是否SqlServer2005
                //_DB = CheckSql2005(_DB);

                if (!IsSql2005.ContainsKey(ConnName))
                {
                    lock (IsSql2005)
                    {
                        if (!IsSql2005.ContainsKey(ConnName))
                        {
                            IsSql2005.Add(ConnName, CheckSql2005(_DB));
                        }
                    }
                }

                if (IsSql2005.ContainsKey(ConnName) && IsSql2005[ConnName])
                {
                    _DALType = typeof(SqlServer2005);
                    _DB.Dispose();
                    _DB = new SqlServer2005(ConnStr);
                }

                _DB.SqlLog = EnableSqlLog;

                _DBs.Add(ConnName, _DB);

                if (DataBase.Debug)
                {
                    DataBase.WriteLog("创建DB(NotWeb):{0}", _DB.ID);
                }

                return(_DB);
            }
        }