Ejemplo n.º 1
0
        /// <summary>
        /// 从配置文件中读取连接字符串并创建 MySql 数据库访问器
        /// </summary>
        /// <param name="name">连接字符串配置名称</param>
        /// <param name="configuration">MySql 配置</param>
        /// <returns>MySql 数据库访问器</returns>
        public static MySqlDbExecutor FromConfiguration(string name, MySqlDbConfiguration configuration = null)
        {
            var setting = ConfigurationManager.ConnectionStrings[name];

            if (setting == null)
            {
                throw new InvalidOperationException();
            }

            return(Connect(setting.ConnectionString, configuration));
        }
Ejemplo n.º 2
0
        public MySqlDbExecutor(string connectionString, MySqlDbConfiguration configuration)
            : base(configuration)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException("connectionString");
            }

            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            ConnectionString = connectionString;
            Configuration    = configuration;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 通过指定的用户名和密码登陆 MySql 数据库,以创建 MySql 数据库访问器
        /// </summary>
        /// <param name="server">数据库服务器地址</param>
        /// <param name="port">数据库服务器端口</param>
        /// <param name="database">数据库名称</param>
        /// <param name="userID">登录数据库的用户名</param>
        /// <param name="password">登录数据库的密码</param>
        /// <param name="pooling">是否启用连接池(默认启用)</param>
        /// <param name="configuration">MySql 数据库配置</param>
        /// <returns>MySql 数据库访问器</returns>
        public static MySqlDbExecutor Connect(string server, uint port, string database, string userID, string password, bool pooling = true, MySqlDbConfiguration configuration = null)
        {
            var builder = new MySqlConnectionStringBuilder()
            {
                Server             = server,
                Database           = database,
                IntegratedSecurity = false,
                UserID             = userID,
                Password           = password,
                Pooling            = pooling
            };

            return(Connect(builder.ConnectionString, configuration));
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 通过指定的连接字符串构建器创建 MySql 数据库访问器
 /// </summary>
 /// <param name="builder">连接字符串构建器</param>
 /// <param name="configuration">MySql 配置</param>
 /// <returns>MySql 数据库访问器</returns>
 public static MySqlDbExecutor Connect(MySqlConnectionStringBuilder builder, MySqlDbConfiguration configuration = null)
 {
     return(Connect(builder.ConnectionString, configuration));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 通过指定的连接字符串并创建 MySql 数据库访问器
 /// </summary>
 /// <param name="connectionString">连接字符串</param>
 /// <param name="configuration">MySql 配置</param>
 /// <returns>MySql 数据库访问器</returns>
 public static MySqlDbExecutor Connect(string connectionString, MySqlDbConfiguration configuration = null)
 {
     return(new MySqlDbExecutor(connectionString, configuration ?? DefaultConfiguration));
 }
Ejemplo n.º 6
0
 static MySqlDb()
 {
     DefaultConfiguration = new MySqlDbConfiguration();
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 通过集成身份验证登陆 MySql 数据库,以创建 MySql 数据库访问器
        /// </summary>
        /// <param name="server">数据库服务器实例名称</param>
        /// <param name="database">数据库名称</param>
        /// <param name="pooling">是否启用连接池(默认启用)</param>
        /// <param name="configuration">MySql 数据库配置</param>
        /// <returns>MySql 数据库访问器</returns>
        public static MySqlDbExecutor Connect(string server, string database, bool pooling = true, MySqlDbConfiguration configuration = null)
        {
            var builder = new MySqlConnectionStringBuilder()
            {
                Server             = server,
                Database           = database,
                IntegratedSecurity = true,
                Pooling            = pooling
            };

            return(Connect(builder.ConnectionString, configuration));
        }
Ejemplo n.º 8
0
 public MySqlDbExecutorWithTransaction(MySqlDbTransactionContext transaction, MySqlDbConfiguration configuration)
     : base(transaction.Connection.ConnectionString, configuration)
 {
     _transaction = transaction;
 }
Ejemplo n.º 9
0
 internal MySqlDbTransactionContext(string connectionString, MySqlDbConfiguration configuration)
 {
     Connection = new MySqlConnection(connectionString);
     _executor  = new MySqlDbExecutorWithTransaction(this, configuration);
 }