In my Azure SQL Managed Instance, I'm unable to create CONTAINED
databases and use ordinary logins and passwords with them (not Azure AD users).
In SSMS > New Database > Options, the Containment type
option is grayed out.
If I create a database with T-SQL:
CREATE DATABASE [Test] CONTAINMENT = PARTIAL
creation succeeds but containment always shows as none and I cannot create users.
I did enable contained database like so:
EXEC sys.sp_configure N'contained database authentication', N'1'
GO
RECONFIGURE WITH OVERRIDE
GO
and even restarted the instance.
And SSMS, [Instance Name] > Properties > Advanced > Containment > Enable Contained Databases is True
.
I also verified that creating users - exactly as described in the documentation (see the "Managed Instance" section) - fails:
Create user [TestUser] With password = 'Test.12345'
fails with the message
You can only create a user with a password in a contained database.
Azure SQL Managed Instance behaves like SQL Server on-premises in the context of contained databases.
However this either is clearly not the case or I'm missing some configuration setting somewhere.
Update 2023-03-15
I killed the instance and created a new one, this time selecting ONLY SQL Server Authentication as an option at the instance-level, rather than mixed-mode authentication.
I was finally able to use contained databases with SQL logins but I first had to enable contained databases for the instance like I normally would. Then I was able to create the database with CONTAINMENT=PARTIAL
and use CREATE USER
normally (although oddly the database still shows as Containment: None
in SSMS).
Would appreciate if someone in the know could confirm if the reason it wasn't working before was because I enabled mixed-mode authentication. Also it seems the answer below is incorrect insofar as saying that containment doesn't have to be explicitly enabled. But what I would really like is clarification so that we know how to configure instances properly in the future. Clearly there is some erroneous or at minimum undocumented behavior going on with respect to contained databases - which my application relies on extensively for row-level security - in a managed instance. Thanks.