Then, connect to the server as user: smurf using SSMS and default database to localDb and try to run the procedure. You will notice that the connection isn’t to the contained database; it is to the server and you are in the context of the contained database. Using EXECUTE AS will give you the same effect:
EXECUTE AS USER = ’PapaSmurf’;goEXECUTE dbo.ExternalDb$TestCrossDatabase;GOREVERT;GO
You will see that it behaves the exact same way and gives you a result to the query. However, connecting with a contained user is a different challenge. First, create a contained user, and then give it rights to execute the procedure:
CREATE USER Gargamel WITH PASSWORD = ’Nasty1$’;GOGRANT EXECUTE ON dbo.ExternalDb$TestCrossDatabase to Gargamel;
Next, change ...
Get Pro SQL Server Relational Database Design and Implementation, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.