예제 #1
0
        internal static void SetDefaultAnsiSettings(IDbConnection conn, bool isSqlDw)
        {
            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.Instance.GetQueryTimeoutSeconds(conn);
                if (!isSqlDw)
                {
                    cmd.CommandText = @"SET ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, ARITHABORT, CONCAT_NULL_YIELDS_NULL, QUOTED_IDENTIFIER ON;
SET NUMERIC_ROUNDABORT OFF;";
                }
                else
                {
                    cmd.CommandText = @"SET ANSI_NULLS ON; SET ANSI_PADDING ON; SET ANSI_WARNINGS ON; SET ARITHABORT ON; SET CONCAT_NULL_YIELDS_NULL ON; SET QUOTED_IDENTIFIER ON;"; //SQL DW does not support NUMERIC_ROUNDABORT
                }
                cmd.ExecuteNonQuery();
            }
        }
 private ReliableSqlCommand(ReliableSqlConnection connection, int dummy)
 {
     if (connection != null)
     {
         _connection = connection;
         _command    = connection.CreateSqlCommand();
     }
     else
     {
         _command = new SqlCommand();
     }
 }
예제 #3
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.Instance.GetQueryTimeoutSeconds(conn);
                cmd.ExecuteNonQuery();
            }
        }
 public ReliableSqlCommand(ReliableSqlConnection connection)
     : this(connection, Dummy)
 {
     Contract.Requires(connection != null);
 }