I have 2 Azure SQL instances :
db-main
which is my main DB, containing bothmy-db
andmaster
databases.db-replica
which contains a readonly replicamy-db@db-main
I have currently a user my-db-admin
having db_owner
role on my-db
database.
I would like to create a specific login (and, if needed, a linked user to this login) with access to only the replicated my-db@db-replica
database.
I tried multiple options which are not working so far :
- Option 1
I tried creating a login on db-main
+ a user on my-db@db-main
+ granting access to my the database... which is then replicated to my-db@db-replica
:
-- To execute on db-main :
use master;
CREATE LOGIN [my-replica-login] WITH PASSWORD='abc';
use my-db;
CREATE USER [my-replica-user] for login [my-replica-login];
EXEC sp_addrolemember 'db_datareader', 'my-replica-user';
I was then able to connect to db-replica
with my-replica-user
but :
- for some (unknown) reasons it was not having access to
my-db@db-replica
Microsoft.Data.SqlClient.SqlException (0x80131904): The server principal "my-replica-user" is not able to access the database "my-db" under the current security context.
Cannot open database "my-db" requested by the login. The login failed.
Login failed for user 'my-replica-user'.
even if this was the case, I would have preferred to not share credentials between
db-main
anddb-replica
Option 2
I tried creating my-replica-user
only on db-replica
... but given that this DB is readonly, it was not possible.
Do you have any idea on how I may sort this out ?