Esempio n. 1
0
        /// <summary>
        /// Open connection asynchronous.
        /// </summary>
        /// <returns>MySqlConnection completed.</returns>
        public async Task <MySqlConnection> GetAsync(string databaseName = null)
        {
            MySqlConnection conn = new MySqlConnection(_connectionString);

            await conn.OpenAsync();

            if (!string.IsNullOrEmpty(databaseName))
            {
                await conn.ChangeDataBaseAsync(databaseName);
            }
            else if (!string.IsNullOrEmpty(_databaseName))
            {
                await conn.ChangeDataBaseAsync(_databaseName);
            }

            return(conn);
        }
Esempio n. 2
0
 public static async Task PrepareConnection(MySqlConnection mySqlConnection, string gameDbName)
 {
     if (mySqlConnection.Database != gameDbName)
     {
         // 切换数据库
         await mySqlConnection.ChangeDataBaseAsync(gameDbName);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="users"></param>
        private async static void BulkInsertAsync(IEnumerable <User> users)
        {
            using (
                var con = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnString"].ConnectionString)
                )
            {
                await con.OpenAsync();

                await con.ChangeDataBaseAsync(dbName);

                var transaction = await con.BeginTransactionAsync();

                foreach (var user in users)
                {
                    con.Insert(user, builder => builder.AttachToTransaction(transaction));
                }

                transaction.Commit();

                con.Close();
            }
        }
 // Baseline connector capitalizes the 'B' in 'Database'
 public static Task ChangeDatabaseAsync(this MySqlConnection connection, string databaseName) => connection.ChangeDataBaseAsync(databaseName);