Exemplo n.º 1
0
        void GetBaseDBByDBType()
        {
            bool bOK = false;

            try
            {
                DataBaseType dataBaseType = CurDalParas.CurDatabaseType;
                switch (dataBaseType)
                {
                case DataBaseType.SqlServer:
                    baseDB = new SqlServerHelper <T>(conStr);
                    break;

                case DataBaseType.Oracle:
                    // baseDB = new OracleHelperFactory<T>(conStr).GetInstance();
                    baseDB = OracleHelperFactory <T> .GetInstance(conStr);

                    break;

                case DataBaseType.MySql:
                    baseDB = new MySqlHelper <T>(conStr);
                    break;
                }
                bOK = true;
            }
            catch
            {
            }
            if (!bOK || baseDB == null)
            {
                string msg = "您配置" + typeof(T).Name + "的数据库类型为【" + CurDalParas.CurDatabaseType.ToString() + "】,但代码中尚未实现。";
                LogCom.WriteModelToFileForDebug(new { 内容 = msg });
                throw new Exception(msg);
            }
        }
Exemplo n.º 2
0
        public IDBAccessDal <T> DBAccessFactory()
        {
            if (dBAccess == null)
            {
                lock (locker)
                {
                    if (dBAccess == null)
                    {
                        DBAccessType dBAccessType = AppConfig.GetFinalConfig("DBAccessTypeKey", DBAccessType.ADONET, LogApi.GetDBAccessType());
                        string       exMsg        = "";
                        try { dBAccess = GetDalByDBAccessType(dBAccessType); }
                        catch (Exception ex) { exMsg = ", " + ex.Message; }

                        string msg = typeof(T).Name + "的数据库访问方式为【" + dBAccessType.ToString() + "】" + exMsg;
                        LogCom.WriteModelToFileForDebug(new { 内容 = msg });
                    }
                }
            }
            return(dBAccess);
        }
Exemplo n.º 3
0
        public static DBGeneral GetDBGeneralInfo(DBType dbType)
        {
            if (DBGeneralDic.ContainsKey(dbType))
            {
                return(DBGeneralDic[dbType]);
            }

            DataBaseType curDBType = DataBaseType.SqlServer;

            if (dbType == DBType.LogTrace)
            {
                curDBType = AppConfig.GetFinalConfig("UserCfg_TraceDBTypeKey", DataBaseType.SqlServer, LogApi.GetUserCfg_TraceDBTypeKey());
            }
            else
            {
                curDBType = AppConfig.GetFinalConfig("UserCfg_MonitorDBTypeKey", DataBaseType.SqlServer, LogApi.GetUserCfg_MonitorDBTypeKey());
            }

            DBGeneral dBGeneral = new DBGeneral()
            {
                DataBaseType = curDBType
            };

            if (curDBType == DataBaseType.SqlServer)
            {
                dBGeneral.SchemaName = "dbo";
            }
            else if (curDBType == DataBaseType.Oracle)
            {
                dBGeneral.SchemaName = "scott";
            }
            else if (curDBType == DataBaseType.MySql)
            {
                // dBGeneral.SchemaName = "";
            }
            DBGeneralDic.Add(dbType, dBGeneral);
            string msg = dbType.ToString() + "的数据库类型为【" + dBGeneral.DataBaseType.ToString() + "】";

            LogCom.WriteModelToFileForDebug(new { 内容 = msg });
            return(dBGeneral);
        }