Skip to content

Idle Connection Resiliency doesn't work with Column Encryption enabled connection #577

@yukiwongky

Description

@yukiwongky

In a connection with Column Encryption enabled, idle Connection Resiliency doesn't seem to work. Following is a simple repro script.

<?php
$conn_break = new PDO("sqlsrv:server = $server; Database = $databaseName;", $uid, $pwd);

// generate table
$tbname = "test_connres2";
$conn_break->query("DROP TABLE $tbname");
$conn_break->query("CREATE TABLE $tbname (c1 int)");
$sql = "INSERT INTO $tbname VALUES (?)";
$stmt = $conn_break->prepare($sql);
$intval = 100;
$stmt->execute(array($intval));

$ceConnectionInfo = "ColumnEncryption=Enabled;";
$crConnectionInfo = "ConnectRetryCount = 10; ConnectRetryInterval = 10;";

try {
    $conn = new PDO("sqlsrv:server = $server; Database = $databaseName; $ceConnectionInfo $crConnectionInfo", $uid, $pwd);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    echo "Could not connect.\n";
    print_r($e->getMessage());
}

// break connection
$stmt = $conn->query("SELECT @@SPID");
$obj = $stmt->fetch(PDO::FETCH_NUM);
$spid = $obj[0];
$conn_break->query("KILL $spid");
sleep(1);

$query2 = "SELECT * FROM $tbname";
try {
    $stmt2 = $conn->prepare($query2, array( PDO::ATTR_CURSOR=> PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE=> PDO::SQLSRV_CURSOR_BUFFERED ));
    $stmt2->execute();
} catch (PDOException $e) {
    echo "Error executing statement 2.\n";
    print_r($e->getMessage());
}

unset($conn);
unset($conn_break);

?>

When trying to retrieve from $tbname in a broken connection (which the driver should try to reconnect because of the idle connection resiliency key words ConnectRetryCount and ConnectRetryInterval) execution gets stuck at the line $stmt2->execute();. When Column Encryption is not enabled however, there is no problem retrieving the $tbname.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions