Skip to main content
Delphix

VDB Provision Fails When Using Contained Database in SQL Server (KBA1758)

 

KBA

KBA#1758

Applicable Delphix Versions

Click here to view the versions of the Delphix engine to which this article applies
Major Release All Sub Releases

5.2

5.2.2.0, 5.2.2.1, 5.2.3.0, 5.2.4.0, 5.2.5.0, 5.2.5.1, 5.2.6.0, 5.2.6.1

5.1

5.1.0.0, 5.1.1.0, 5.1.2.0, 5.1.3.0, 5.1.4.0, 5.1.5.0, 5.1.5.1, 5.1.6.0, 5.1.7.0, 5.1.8.0, 5.1.8.1, 5.1.9.0, 5.1.10.0

5.0

5.0.1.0, 5.0.1.1, 5.0.2.0, 5.0.2.1, 5.0.2.2, 5.0.2.3, 5.0.3.0, 5.0.3.1, 5.0.4.0, 5.0.4.1 ,5.0.5.0, 5.0.5.1, 5.0.5.2, 5.0.5.3, 5.0.5.4

4.3

4.3.1.0, 4.3.2.0, 4.3.2.1, 4.3.3.0, 4.3.4.0, 4.3.4.1, 4.3.5.0

4.2

4.2.0.0, 4.2.0.3, 4.2.1.0, 4.2.1.1, 4.2.2.0, 4.2.2.1, 4.2.3.0, 4.2.4.0 , 4.2.5.0, 4.2.5.1

4.1

4.1.0.0, 4.1.2.0, 4.1.3.0, 4.1.3.1, 4.1.3.2, 4.1.4.0, 4.1.5.0, 4.1.6.0

Troubleshooting Container Database

In Delphix Engine version 5.2.6.1 and earlier, VDB Provision operations may fail if the parent database was configured to use the SQL Server Contained Database feature.

When this occurs, the Provision operation will fail with the following error:

The containment state of database 'Vdb0_4KC' does not match the value in master. Contained database functionality will not work as expected. Detach and re-attach the database to correct the database state in master.

Resolution

To resolve this error, upgrade to Delphix Engine version 5.3 or later, where this issue has been fixed.

Until an upgrade can be performed, the following workarounds can be used:

Manual workaround (Delphix Engine 5.2.6.1 and earlier):

Manually detach and re-attach the database from SQL Server Management Studio. This should correct the database containment status and allow subsequent VDB operations, such as snapshots, to continue.

Hook operation workaround (Delphix Engine 5.2.6.1 and earlier): 

The following Configure Clone hook script can be used to remove the manual process of the detach and attach at the SQL Server level.

# Create variables and assign the environment variables
$INSTANCE_HOST = $env:VDB_INSTANCE_HOST
$INSTANCE_PORT = $env:VDB_INSTANCE_PORT
$INSTANCE_NAME = $env:VDB_INSTANCE_NAME
$DATABASE_NAME = $env:VDB_DATABASE_NAME
function die {
    "Error: $($args[0])"
    exit 1
}
function verifySuccess {
    if (!$?) {
        die "$($args[0])"
    }
}
sqlcmd -b -E -d master -S "tcp:$INSTANCE_HOST\$INSTANCE_NAME,$INSTANCE_PORT" -q "DECLARE @physical_name nvarchar(300);
SELECT @physical_name = physical_name FROM sys.master_files WHERE database_id = DB_ID('$DATABASE_NAME') and file_id = 1;
ALTER DATABASE [$DATABASE_NAME] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
EXEC sp_detach_db [$DATABASE_NAME];
EXEC ('CREATE DATABASE [$DATABASE_NAME] ON (FILENAME = ''' + @physical_name + ''') For ATTACH;');
ALTER DATABASE [$DATABASE_NAME] SET MULTI_USER WITH ROLLBACK IMMEDIATE;"
VerifySuccess "sqlcmd failed"