/// <summary> /// 获取企业的数据库配置信息 /// </summary> /// <returns></returns> public static string GetBusinnessConStr(string applicationTag) { applicationTag = applicationTag.ToUpper(); string CacheKey = "SAAS_ConnectionString_" + applicationTag + "_" + Common.CallContextHelper.GetAutoTag(); dataCache = new DataCacheCore( new CacheOption { CacheType = CacheType.Redis, CancelProductKey = true, CancelEnterpriseKey = true, DefaultDb = 0, ReadWriteHosts = SAASInfo.GetSystemValue("RedisCacheReadWriteHosts"), ReadOnlyHosts = SAASInfo.GetSystemValue("RedisCacheReadOnlyHosts"), }); object objModel = dataCache.GetCache(CacheKey); if (objModel == null || String.IsNullOrWhiteSpace(objModel.ToString())) { try { DataSet ds = Query( "select * from SA_EnterpriseDBConfig where EnterpriseId=@EnterpriseId and [State]=1 and ApplicationTag=@ApplicationTag", new SqlParameter[] { new SqlParameter("@EnterpriseId", Common.CallContextHelper.GetAutoTag()), new SqlParameter("@ApplicationTag", applicationTag) }); if (ds == null || ds.Tables.Count <= 0 || ds.Tables[0].Rows.Count > 1) { return(null); } foreach (DataRow item in ds.Tables[0].Rows) { objModel = "server=" + item["RemoteDB_IP"] + ";database=" + item["DBName"] + ";uid=" + item["UserInstance"] + ";pwd=" + item["Passworld"]; break; } if (objModel != null && !String.IsNullOrWhiteSpace(objModel.ToString())) { dataCache.SetCache(CacheKey, objModel, DateTime.MaxValue, TimeSpan.Zero); } } catch (Exception ex) { Log.LogHelper.AddErrorLog("获取连接地址失败:" + ex.Message, "详细错误为:" + ex.StackTrace); throw ex; } } return(Common.Globals.SafeString(objModel, "")); }
public static void Init(CacheOption option) { dateCache = new DataCacheCore(option); CacheType = option.CacheType; }