diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 52ad200cf7f..69a91417184 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -136,11 +136,11 @@ public function lastInsertId($name = null) if ($name !== null) { $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?'); $stmt->execute([$name]); - - return $stmt->fetchColumn(); + } else { + $stmt = $this->query('SELECT @@IDENTITY'); } - return $this->lastInsertId->getId(); + return $stmt->fetchColumn(); } /**