Beispiel #1
0
        internal static void SetDefaultAnsiSettings(IDbConnection conn)
        {
            Validate.IsNotNull(nameof(conn), conn);

            // Make sure we use the underlying connection as ReliableConnection.Open also calls
            // this method
            ReliableSqlConnection reliableConn = conn as ReliableSqlConnection;

            if (reliableConn != null)
            {
                conn = reliableConn._underlyingConnection;
            }

            // Configure the connection with proper ANSI settings and lock timeout
            using (IDbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandTimeout = CachedServerInfo.GetQueryTimeoutSeconds(conn);
                cmd.CommandText    = @"SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;";
                cmd.ExecuteNonQuery();
            }
        }
Beispiel #2
0
        internal static void SetLockAndCommandTimeout(IDbConnection conn)
        {
            Validate.IsNotNull(nameof(conn), conn);

            // Make sure we use the underlying connection as ReliableConnection.Open also calls
            // this method
            ReliableSqlConnection reliableConn = conn as ReliableSqlConnection;

            if (reliableConn != null)
            {
                conn = reliableConn._underlyingConnection;
            }

            const string setLockTimeout = @"set LOCK_TIMEOUT {0}";

            using (IDbCommand cmd = conn.CreateCommand())
            {
                cmd.CommandText    = string.Format(CultureInfo.InvariantCulture, setLockTimeout, AmbientSettings.LockTimeoutMilliSeconds);
                cmd.CommandType    = CommandType.Text;
                cmd.CommandTimeout = CachedServerInfo.GetQueryTimeoutSeconds(conn);
                cmd.ExecuteNonQuery();
            }
        }