Exemplo n.º 1
0
        /// <summary>
        /// 通过name 、数据库连接串、提供者名称, 创建database实例
        /// </summary>
        /// <param name="name">DBDatabase名称,唯一,主键</param>
        /// <param name="connectionString">数据库连接串</param>
        /// <param name="providername">数据库提供者名称</param>
        /// <returns>database实例</returns>
        public static Database Create(string name, string connectionString, string strDBtype)
        {
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString", String.Format(DbError.ConnstrNull));
            }

            if (string.IsNullOrEmpty(strDBtype))
            {
                throw new ArgumentNullException("providername", String.Format(DbError.ProviderNameNull));
            }
            string providername = getProviderName(strDBtype);

            System.Data.Common.DbProviderFactory fact = System.Data.Common.DbProviderFactories.GetFactory(providername);

            if (null == fact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForConn, providername));
            }

            DBProvider datafact = DBProvider.GetProvider(providername);

            if (null == datafact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForDBFactory, providername));
            }

            Database db = datafact.CreateDatabase(connectionString, providername, fact);

            //设置名字
            db.Name = name;

            //返回实例
            return(db);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 通过name 、数据库连接串、提供者名称, 创建database实例
        /// </summary>
        /// <param name="name">DBDatabase名称,唯一,主键</param>
        /// <param name="connectionString">数据库连接串</param>
        /// <param name="providername">数据库提供者名称</param>
        /// <returns>database实例</returns>
        public static Database Create(string name, string strDBType, string dbhost, string dbname, string dbuser, string dbpwd)
        {
            if (string.IsNullOrEmpty(strDBType))
            {
                throw new ArgumentNullException("DBType", String.Format(DbError.ConnstrNull));
            }
            string providername = getProviderName(strDBType);

            if (string.IsNullOrEmpty(strDBType))
            {
                throw new ArgumentNullException("providername", String.Format(DbError.ProviderNameNull));
            }

            System.Data.Common.DbProviderFactory fact = System.Data.Common.DbProviderFactories.GetFactory(providername);

            if (null == fact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForConn, providername));
            }

            DBProvider datafact = DBProvider.GetProvider(providername);

            dbpwd = DataBaseCache.DealDecodePWD(dbpwd);
            string connstring = datafact.getConnString(dbhost, dbname, dbuser, dbpwd);

            if (null == datafact)
            {
                throw new ArgumentNullException("providername", String.Format(DbError.InvalidProviderNameForDBFactory, providername));
            }

            Database db = datafact.CreateDatabase(connstring, providername, fact);

            //设置名字
            db.Name = name;

            //返回实例
            return(db);
        }