diff --git a/apps/dav/lib/carddav/addressbookimpl.php b/apps/dav/lib/carddav/addressbookimpl.php
index 1d7b55c1a5d3a8c72acd005270f438f0bc572e7a..795a30064b71802923859922a4f4722dbf9066ce 100644
--- a/apps/dav/lib/carddav/addressbookimpl.php
+++ b/apps/dav/lib/carddav/addressbookimpl.php
@@ -178,7 +178,7 @@ class AddressBookImpl implements IAddressBook {
 	protected function createUid() {
 		do {
 			$uid = $this->getUid();
-			$contact = $this->backend->getContact($uid . '.vcf');
+			$contact = $this->backend->getContact($this->getKey(), $uid . '.vcf');
 		} while (!empty($contact));
 
 		return $uid;
diff --git a/apps/dav/lib/carddav/carddavbackend.php b/apps/dav/lib/carddav/carddavbackend.php
index aa2490ab11a11a2a6af59ab6820a67dbcf6da660..78706ae6bff64dc6137a37d55f7e6f045dfadbd9 100644
--- a/apps/dav/lib/carddav/carddavbackend.php
+++ b/apps/dav/lib/carddav/carddavbackend.php
@@ -548,7 +548,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
 	 */
 	function deleteCard($addressBookId, $cardUri) {
 		try {
-			$cardId = $this->getCardId($cardUri);
+			$cardId = $this->getCardId($addressBookId, $cardUri);
 		} catch (\InvalidArgumentException $e) {
 			$cardId = null;
 		}
@@ -807,15 +807,16 @@ class CardDavBackend implements BackendInterface, SyncSupport {
 	/**
 	 * return contact with the given URI
 	 *
+	 * @param int $addressBookId
 	 * @param string $uri
 	 * @returns array
 	 */
-	public function getContact($uri) {
+	public function getContact($addressBookId, $uri) {
 		$result = [];
 		$query = $this->db->getQueryBuilder();
 		$query->select('*')->from($this->dbCardsTable)
-				->where($query->expr()->eq('uri', $query->createParameter('uri')))
-				->setParameter('uri', $uri);
+				->where($query->expr()->eq('uri', $query->createNamedParameter($uri)))
+				->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
 		$queryResult = $query->execute();
 		$contact = $queryResult->fetch();
 		$queryResult->closeCursor();
@@ -851,7 +852,7 @@ class CardDavBackend implements BackendInterface, SyncSupport {
 	 * @param string $vCardSerialized
 	 */
 	protected function updateProperties($addressBookId, $cardUri, $vCardSerialized) {
-		$cardId = $this->getCardId($cardUri);
+		$cardId = $this->getCardId($addressBookId, $cardUri);
 		$vCard = $this->readCard($vCardSerialized);
 
 		$this->purgeProperties($addressBookId, $cardId);
@@ -913,13 +914,15 @@ class CardDavBackend implements BackendInterface, SyncSupport {
 	/**
 	 * get ID from a given contact
 	 *
+	 * @param int $addressBookId
 	 * @param string $uri
 	 * @return int
 	 */
-	protected function getCardId($uri) {
+	protected function getCardId($addressBookId, $uri) {
 		$query = $this->db->getQueryBuilder();
 		$query->select('id')->from($this->dbCardsTable)
-			->where($query->expr()->eq('uri', $query->createNamedParameter($uri)));
+			->where($query->expr()->eq('uri', $query->createNamedParameter($uri)))
+			->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId)));
 
 		$result = $query->execute();
 		$cardIds = $result->fetch();
diff --git a/apps/dav/tests/unit/carddav/addressbookimpltest.php b/apps/dav/tests/unit/carddav/addressbookimpltest.php
index ff7b982abd4ea18cccd07e088f3dbd3703b0b566..f2c739e046d57bc7079e0572078a902690d304b7 100644
--- a/apps/dav/tests/unit/carddav/addressbookimpltest.php
+++ b/apps/dav/tests/unit/carddav/addressbookimpltest.php
@@ -261,7 +261,7 @@ class AddressBookImplTest extends TestCase {
 		// simulate that 'uid0' already exists, so the second uid will be returned
 		$this->backend->expects($this->exactly(2))->method('getContact')
 			->willReturnCallback(
-				function($uid) {
+				function($id, $uid) {
 					return ($uid === 'uid0.vcf');
 				}
 			);
diff --git a/apps/dav/tests/unit/carddav/carddavbackendtest.php b/apps/dav/tests/unit/carddav/carddavbackendtest.php
index f7e59b3fda9ba8d6e82e49a5555b76f1e5278ae3..3b5395fb09eec2435c239669a43bbfe694068568 100644
--- a/apps/dav/tests/unit/carddav/carddavbackendtest.php
+++ b/apps/dav/tests/unit/carddav/carddavbackendtest.php
@@ -44,7 +44,7 @@ class CardDavBackendTest extends TestCase {
 	/** @var CardDavBackend */
 	private $backend;
 
-	/** @var  Principal | \PHPUnit_Framework_MockObject_MockObject */
+	/** @var Principal | \PHPUnit_Framework_MockObject_MockObject */
 	private $principal;
 
 	/** @var  IDBConnection */
@@ -268,7 +268,7 @@ class CardDavBackendTest extends TestCase {
 		// create a new address book
 		$this->backend->expects($this->once())
 			->method('getCardId')
-			->with($uri)
+			->with($bookId, $uri)
 			->willThrowException(new \InvalidArgumentException());
 		$this->backend->expects($this->exactly(2))
 			->method('addChange')
@@ -445,14 +445,14 @@ class CardDavBackendTest extends TestCase {
 		$id = $query->getLastInsertId();
 
 		$this->assertSame($id,
-			$this->invokePrivate($this->backend, 'getCardId', ['uri']));
+			$this->invokePrivate($this->backend, 'getCardId', [1, 'uri']));
 	}
 
 	/**
 	 * @expectedException InvalidArgumentException
 	 */
 	public function testGetCardIdFailed() {
-		$this->invokePrivate($this->backend, 'getCardId', ['uri']);
+		$this->invokePrivate($this->backend, 'getCardId', [1, 'uri']);
 	}
 
 	/**
@@ -596,7 +596,7 @@ class CardDavBackendTest extends TestCase {
 			$query->execute();
 		}
 
-		$result = $this->backend->getContact('uri0');
+		$result = $this->backend->getContact(0, 'uri0');
 		$this->assertSame(7, count($result));
 		$this->assertSame(0, (int)$result['addressbookid']);
 		$this->assertSame('uri0', $result['uri']);
@@ -606,7 +606,7 @@ class CardDavBackendTest extends TestCase {
 	}
 
 	public function testGetContactFail() {
-		$this->assertEmpty($this->backend->getContact('uri'));
+		$this->assertEmpty($this->backend->getContact(0, 'uri'));
 	}
 
 	public function testCollectCardProperties() {