3

I'm developing a cloud service using Azure Mobile Services, and in order to test it quickly and debug it, I want to deploy it in my local computer. I select the project, hit F5, got it running in IIS express in my local PC. I execute the cliente against my local URI address of the IIS service and when I try to insert a value, this exception appears if I try to retrieve 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 the Initialization of the controller and found out that mobile services deploys a LocalDb instance with this connection info on 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 is not able to find this DataBase if I try to connect with this connection string to the LocalDB via the SQL Management Studio

I'm able to access to the LocalDb instance with the SQL management studio running this command on CMD and retrieving the Connection for the LocalDB

SqlLocalDB.exe info v11.0

Eitherway, on the SQL Management Studio I'm not able to see any DataBase relating my controller of the Mobile Services. I searched on google and the only related link I found was this but is not working... Does anybody know what's happening?

Thank you so much

3 Answers 3

17

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

To fix this, go into the web.config and edit the appsetting named "MS_MobileServiceName" taking out the periods. This is the value used as the SQL schema name for your mobile service tables in the database. It can't have periods or other special characters in it.

I generally try to make this the same as the name of the mobile service I'll deploy to, but it's not technically required.

2
  • 1
    Un freakin real! Thank you so much. I've spent all day creating and recreating and testing and couldn't figure out what this error is. They really should prevent you from putting in periods or at least clean the value for service name in the webconfig.
    – jmichas
    Sep 19, 2014 at 22:21
  • Hi, I tested it and really worked! thak you so much for the answer! It would be could if as jmichas says, they prevent you from putting periods... Sep 20, 2014 at 10:41
2

For whatever reason, I couldn't get this working using the accepted answer. I assume this has something to do with the disclaimer in web.config which states:

After publishing to Mobile Services, these settings will be overridden by the values specified in the portal.

However, I did find another work around in the MobileServiceContext file 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 imagine there's a way to influence the output of GetSchemaName() but, considering how much effort it took to resolve this problem, I am perfectly content with this solution for now.

1
  • FYI, after installing the Azure SDK updates yesterday and redeploying my mobile service application, I started getting duplicate tables in my database. In addition to the schema specified in the HasDefaultSchema call, I also had the same tables in the dbo schema; even the __MigrationHistory table was duplicated. For now, I've removed the HasDefaultSchema call and am accepting the default dbo. Nov 15, 2014 at 14:44
2

If you've changed the MS_MobileServiceName in config to remove the periods, and you're still getting the error, you'll need to re-run the scaffolding for the Initial migration in the package manager console:

Add-Migration Initial -Force

From what I could see, the scaffolding generates an embedded .resx that still has your old schema name (DefaultSchema), and a snapshot (Target) that is referenced in the designer code. Just changing the DefaultSchema didn't solve the issue for me, but re-running the scaffolding did.

I also added Table annotations to my models, but I don't think that was the issue. And probably isn't ideal if your service is already live.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.