Esempio n. 1
0
        /// <summary>
        /// Creates and opens a SQL connection.
        /// </summary>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        /// <remarks>
        /// The caller of this method is responsible for closing the connection.
        /// </remarks>
        async Task <OleDbConnection> CreateConnectionAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            var con = new OleDbConnection(ConnectionString);
            await con.OpenAsync(cancellationToken).ConfigureAwait(false);

            if (m_ServerDefaultSettings == null)
            {
                var temp = new OleDbSqlServerEffectiveSettings();
                await temp.ReloadAsync(con, null);

#if !Thread_Missing
                Thread.MemoryBarrier();
#endif
                m_ServerDefaultSettings = temp;
            }

            var sql = BuildConnectionSettingsOverride();

            if (sql.Length > 0)
            {
                using (var cmd = new OleDbCommand(sql.ToString(), con))
                    await cmd.ExecuteNonQueryAsync();
            }

            return(con);
        }
Esempio n. 2
0
        public async Task <OleDbSqlServerEffectiveSettings> GetEffectiveSettingsAsync()
        {
            var result = new OleDbSqlServerEffectiveSettings();

            using (var con = await CreateConnectionAsync().ConfigureAwait(false))
                await result.ReloadAsync(con, null).ConfigureAwait(false);
            return(result);
        }
Esempio n. 3
0
    private partial async Task <AbstractConnection> OnCreateConnectionAsync(CancellationToken cancellationToken)
    {
        var con = new OleDbConnection(ConnectionString);
        await con.OpenAsync(cancellationToken).ConfigureAwait(false);

        if (m_ServerDefaultSettings == null)
        {
            var temp = new OleDbSqlServerEffectiveSettings();
            await temp.ReloadAsync(con, null).ConfigureAwait(false);

            Thread.MemoryBarrier();
            m_ServerDefaultSettings = temp;
        }

        var sql = BuildConnectionSettingsOverride();

        if (sql != null)
        {
            using (var cmd = new OleDbCommand(sql, con))
                await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);
        }

        return(con);
    }