Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
yukiwongky opened this issue Oct 24, 2017 · 1 comment

Comments

@yukiwongky
Copy link
Contributor

yukiwongky commented Oct 24, 2017

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.

@yitam
Copy link
Contributor

yitam commented Apr 10, 2018

Tested with ODBC 17.1 and verified that this had been fixed.

@yitam yitam closed this as completed Apr 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants