示例#1
0
        public DbClinet()
        {
            Exception = new DboException();
            switch (ConfigurationManager.ConnectionStrings[DbClinet.WebConfigKey].ProviderName)
            {
            case "System.Data.SqlClient": objFactory = SqlClientFactory.Instance;
                break;

            case "System.Data.OleDb": objFactory = OleDbFactory.Instance;
                break;

            case "System.Data.OracleClient": objFactory = OracleClientFactory.Instance;
                break;

            case "System.Data.Odbc": objFactory = OdbcFactory.Instance;
                break;
            }
            if (objFactory == null)
            {
                Exception.Exception("未初始化数据连接池");
            }
            this.con = objFactory.CreateConnection();
            this.con.ConnectionString = ConfigurationManager.ConnectionStrings[DbClinet.WebConfigKey].ConnectionString;
            this.cmd            = objFactory.CreateCommand();
            this.cmd.Connection = con;
        }
示例#2
0
        /// <summary>
        /// 构造方法
        /// </summary>
        /// <param name="con">连接字符串</param>
        /// <param name="provider">数据库类型</param>
        public DbClinet(string conString, Providers provider)
        {
            Exception = new DboException();
            switch (provider)
            {
            case Providers.SqlServer: objFactory = SqlClientFactory.Instance; break;

            case Providers.ODBC: objFactory = OdbcFactory.Instance; break;

            case Providers.OleDb: objFactory = OleDbFactory.Instance; break;

            case Providers.Oracle: objFactory = OracleClientFactory.Instance; break;
            }
            if (objFactory == null)
            {
                Exception.Exception("未初始化数据连接池");
            }
            this.con = objFactory.CreateConnection();
            this.con.ConnectionString = conString;
            this.cmd            = objFactory.CreateCommand();
            this.cmd.Connection = con;
        }