Exemple #1
0
        public async Task CreateDatabase(CancellationToken cancellationToken = default)
        {
            await _sqlServerContainer.TryStart(cancellationToken).WithTimeout(3 * 60 * 1000);

            var policy = Policy
                         .Handle <SqlException>()
                         .WaitAndRetryAsync(3, i => TimeSpan.FromSeconds(1));

            await policy.ExecuteAsync(async() =>
            {
                using (var connection = CreateConnection())
                {
                    await connection.OpenAsync(cancellationToken).NotOnCapturedContext();

                    var createCommand = $@"CREATE DATABASE [{_databaseName}]
ALTER DATABASE [{_databaseName}] SET SINGLE_USER
ALTER DATABASE [{_databaseName}] SET COMPATIBILITY_LEVEL=110
ALTER DATABASE [{_databaseName}] SET MULTI_USER";

                    using (var command = new SqlCommand(createCommand, connection))
                    {
                        await command.ExecuteNonQueryAsync(cancellationToken).NotOnCapturedContext();
                    }
                }
            });
        }
        public async Task CreateDatabase(CancellationToken cancellationToken = default)
        {
            await _mysqlContainer.TryStart(cancellationToken).WithTimeout(60 * 1000 * 3);

            var commandText = $"CREATE DATABASE IF NOT EXISTS `{_databaseName}`";

            using (var connection = new MySqlConnection(DefaultConnectionString))
            {
                await connection.OpenAsync(cancellationToken).NotOnCapturedContext();

                using (var command = new MySqlCommand(commandText, connection))
                {
                    await command.ExecuteNonQueryAsync(cancellationToken).NotOnCapturedContext();
                }
            }
        }
Exemple #3
0
            public async Task CreateDatabase(CancellationToken cancellationToken = default)
            {
                await _sqlServerContainer.TryStart(cancellationToken).WithTimeout(3 * 60 * 1000);

                using (var connection = CreateConnection())
                {
                    await connection.OpenAsync(cancellationToken).NotOnCapturedContext();

                    var createCommand = $@"CREATE DATABASE [{_databaseName}]
ALTER DATABASE [{_databaseName}] SET SINGLE_USER
ALTER DATABASE [{_databaseName}] SET COMPATIBILITY_LEVEL=110
ALTER DATABASE [{_databaseName}] SET MULTI_USER";

                    using (var command = new SqlCommand(createCommand, connection))
                    {
                        await command.ExecuteNonQueryAsync(cancellationToken).NotOnCapturedContext();
                    }
                }
            }
Exemple #4
0
        public override async Task CreateDatabase(CancellationToken cancellationToken = default)
        {
            await _mysqlContainer.TryStart(cancellationToken).WithTimeout(60 * 1000 * 3);

            await base.CreateDatabase(cancellationToken);
        }