Exemplo n.º 1
0
        /// <summary>
        /// 根据数据库的逻辑名称创建Database实例
        /// </summary>
        /// <param name="name">数据库逻辑名称</param>
        /// <returns>Database实例</returns>
        public static Database Create(string name)
        {
            ExceptionHelper.CheckStringIsNullOrEmpty(name, "name");

            //// 根据数据驱动名称对应的数据库实体
            //// 如果以后需要开放DeluxeWorks.Db提供自动加载第三方Database类型的话,也仅需要修改这个方法
            //switch (DbConnectionManager.GetDbProviderName(name))
            //{
            //    case "System.Data.SqlClient":
            //        return new SqlDatabase(name);
            //    case "System.Data.OracleClient":
            //        return new OracleDatabase(name);
            //    //case "Oracle.DataAccess.Client":
            //    //    return new ODP.OracleDatabase(name);
            //    default:
            //        throw new NotSupportedException(name + " 所定义的数据驱动不支持");
            //}

            return(DbConnectionManager.GetDataProvider(name) as Database);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据名称得到当前引用的连接
        /// </summary>
        /// <param name="connName">数据库连接名称</param>
        /// <returns>连接对象</returns>
        protected ReferenceConnection GetRefConnectionWithoutTx(string connName)
        {
            ReferenceConnection refConnection = null;

            GraphWithoutTransaction connections = GraphWithoutTx;

            lock (connections)
            {
                if (connections.TryGetValue(connName, out refConnection) == false)
                {
                    DbConnection connection = DbConnectionManager.GetConnection(connName);
                    this.isConnectionCreator = true;

                    refConnection = new ReferenceConnection(connName, connection);
                    connections.Add(connName, refConnection);
                }
                else
                {
                    refConnection.ReferenceCount++;
                }
            }

            return(refConnection);
        }