Two Azure Mobile Services (.NET backend) sharing the same Database

拟墨画扇 提交于 2019-12-03 09:15:07

When a mobile service named 'MSName' is created, a schema with the name 'MSName' is defined in the database, and a user is created with permission to access that schema only. That is the user in the default connection string which the mobile service will use when connecting to the database in the runtime. So if you have a service 'X' and try from it to access the service 'Y', the user it's using will not have permissions to do so.

There are a few options you can do to solve that. One is to find the user for service 'Y' (using one of the SQL server management tools) and grant it access to the schema for 'X'. Another option is to, when creating the context in the mobile service Y not to use the default connection string ("Name=MS_TableConnectionString"), but a connection string which uses the user for 'X'.

Just so that I understand -- you want your two services to access the same set of tables in the same database? Not just using the same database but the same tables?

You can easily reuse the same database but we set each mobile service using it up with a separate schema and permissions to only access that schema so that two services won't inadvertently interfere.

However, it sounds like you want them to access the same tables, right? This means that in addition to changing the schema in your service you also need to set the permissions for the mobile user in the DB to access that schema.

You can get the user using the kudu site under the Environment tab (look for the MS_TableConnectionString connection string):

https://<your service>.scm.azure-mobile.net/Env

And you can set the permissions for that user using the grant command -- you can see an example her:

https://weblogs.asp.net/fredriknormen/database-migration-and-azure-mobile-service-adventure

Hope this helps!

Henrik

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!