Developing with Azure Mobile Services on-premises [.Net backend]

I am developing a cloud service using Azure Mobile Services and in order to quickly test and debug it, I want to deploy it to my local machine. I select the project, press F5, run it in IIS express on my local PC. I am running cliente against my local IIS URI, and when I try to insert a value, this exception appears if I try to fetch or insert a new object:

An exception of type 'System.ArgumentException' occurred in EntityFramework.SqlServer.dll but was not handled in user code 

      

Additional information: The database name 'TR_MyTrip_Server_ExtraData_Service]_Persons_InsertUpdateDelete' is invalid. Database names must be of the form [<schema_name>.]<object_name>.

I debugged controller initialization and found out that mobile services deploy a LocalDb instance with this connection information in the DataBase property of the ServiceContext object:

Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-MyTrip.Server.ExtraData.Service-20140731060708.mdf;Initial Catalog=aspnet-TestProject.Server.ExtraData.Service-20140731060708;Integrated Security=True;MultipleActiveResultSets=True

      

It cannot find this database if I try to connect to this LocalDB connection string via SQL Management Studio

I can access the LocalDb instance using SQL management studio executing this command in CMD and getting the connection for LocalDB

SqlLocalDB.exe info v11.0

      

At the same time, in SQL Management Studio, I cannot see any database associated with my mobile services controller. I searched on google and the only related link I found was this but doesn't work ... Does anyone know what's going on?

Thank you very much

+3


source to share


3 answers


This is a problem when you have a project name with periods in it. Like TestProject.Server.ExtraData.Service.

To fix this, go to the web.config file and edit the appsetting named "MS_MobileServiceName" to extract the periods. This is the value used as the SQL schema name for your mobile service tables in the database. It cannot contain periods or other special characters.



I usually try to do this the same as the name of the mobile service I will deploy to, but this is not technically required.

+16


source


For some reason, I couldn't get this working using the accepted answer. I guess it has something to do with the disclaimer in web.config, which reads:

Once published to Mobile Services, these settings will be overridden by the values ​​specified in the portal.

However, I found another work in the file MobileServiceContext

, where I replaced this line:



string schema = ServiceSettingsDictionary.GetSchemaName();
if (!string.IsNullOrEmpty(schema))
{
    modelBuilder.HasDefaultSchema(schema);
}

      

with a simple string value modelBuilder.HasDefaultSchema('mySchema');

I guess there is a way to influence the output GetSchemaName()

, but considering how much effort it took to solve this problem, I'm happy with this solution at the moment.

+2


source


If you changed the MS_MobileServiceName in config to remove periods and you still get this error, you will need to rerun the scaffolding for the initial migration in the Package Manager Console:

Add-Migration Initial -Force

From what I could see, the scaffolding creates an inline .resx that still has your old schema name (DefaultSchema) and a snapshot (Target) referenced by the developer code. Just changing the DefaultSchema didn't solve the problem for me, but restarting the forests did.

I also added table annotations to my models, but I don't think this was the problem. And it's probably not ideal if your service is already running.

+2


source







All Articles