Ejemplo n.º 1
0
        /// <summary>
        /// 分库路由器,如果操作存在事务,返回的DB连接已在事务中
        /// 数据库主从集群
        /// </summary>
        /// <param name="ODASql"></param>
        /// <returns></returns>
        private IDBAccess DatabaseRouting(ODAScript ODASql)
        {
            ODAConnect conn = GetConnect(ODASql);

            if (_Tran == null)
            {
                return(NewDBConnect(conn.DBtype, conn.ConnectionString));
            }
            else
            {
                this.CheckTransaction(ODASql);
                if (_Tran.TransDB.ContainsKey(conn.ConnectionString))
                {
                    return(_Tran.TransDB[conn.ConnectionString]);
                }
                else
                {
                    IDBAccess DBA = NewDBConnect(conn.DBtype, conn.ConnectionString);
                    DBA.BeginTransaction();
                    _Tran.DoCommit    += DBA.Commit;
                    _Tran.RollBacking += DBA.RollBack;
                    _Tran.TransDB.Add(conn.ConnectionString, DBA);
                    return(DBA);
                }
            }
        }
Ejemplo n.º 2
0
 public ODAContext(DbAType DbType, string ConectionString)
 {
     if (string.IsNullOrWhiteSpace(ConectionString))
     {
         throw new ODAException(30002, "DataBase Conection String should be setted.");
     }
     _Conn = new ODAConnect()
     {
         DBtype           = DbType,
         ConnectionString = ConectionString
     };
     _IsConfig = false;
 }