Staging environment for Azure Mobile Services using Code First Migrations -


i seem have trouble understanding concept azure mobile services using .net backend code first , migrations enabled.

currently have deployed "productive" instance of ams, let's it's called "amd". running @ amd.azure-mobile.net. database structure has been created using enable-migrations , add-migration. fine productive instance, running , functional.

now want create int instance have separate environment tests etc. want name differently, "amdint". should run @ amdint.azure-mobile.net , should have separate database, make impossible break stuff in production.

originally thought pull off this: 1) create new instance under amdint.azure-mobile.net new database go 2) create web.config transform newly created configuration called "int" (primarily change ms_mobileservicename value new name) 3) download publishing profile of new instance, import it, make use "int" configuration , deploy it

the new bits apparently deployed, whenever hit endpoint requires db access, error generated in logs , says

database initialization failed. not initialize 1 or more objects in schema 'amdint'. please ensure database connection string correct. more details on error, please see inner exception. ---> system.invalidoperationexception: database initialization failed. not initialize 1 or more objects in schema 'amdint'. please ensure database connection string correct. more details on error, please see inner exception. ---> system.data.sqlclient.sqlexception: user not have permission perform action.

so used azure user management console (aumc) see if permissions missing user being specified in connection string in configuration tab of new service, user present database. edited user's permissions include every possible right, did not change anything. noticed migrations files specify database schema up() , down() methods. test, changed these strings "amd.tablename" "amdint.tablename" , pretty confident had nailed it.

however, still brought same error. used database user's credentials connection string , opened database editor management console in browser, , saw added rights can edit database schema fine (created , deleted table testing purposes). however, no single table has been created initializer; database blank.

but since able edit, somehow believe either error message insufficient permissions misleading or looking @ wrong place.

does know of way accomplish trying do? don't want have separate visual studio projects production , int, obviously.

i think you're running issue mobile services creates special schema user has rights tables in schema. schema has same name mobile service. so, if 2 databases on same db server, connection string dev mobile service wouldn't work prod, , vice versa.

here suggestions make setup easier:

  1. in azure portal, mobile services doesn't allow modifying connection string creates you, called ms_tableconnectionstring. recommend in case, create new connection string different key , use each of services, e.g., amd_tableconnectionstring. make sure each service, database user has access each schema (more on in minute).

  2. to use new connection string, change super constructor call in dbcontext class, e.g., base("name=amd_tableconnectionstring").

  3. use application setting ms_mobileservicename in web.config and/or azure portal set schema service. use mobile service entity framework initializer.

    note: if you're using separate databases dev , prod, have option of using same schema name both dev , prod instances, might make testing , setup easier.

    either way, database user in connection string must have full permissions whatever schema name specify in ms_mobileservicename.

  4. (you have part working.) make sure mobile services sql generator run. automatically run if set entity framework database initializer, folks have database changes done through db migrations. in case, follow tutorial here: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-how-to-use-code-first-migrations/#using-code-first-migrations-without-an-initializer


Comments