0
votes

I'm trying to use Azure Mobile Apps and Azure Storage to build a backend for my Xamarin.Forms app. I created everything in Azure (Mobile Service, Storage Account, ConnectionString, etc.) and downloaded the default project of the backend (as I chose C# as language) and of the Xamarin.Forms app.

Then I debugged locally the project of the backend and was working, so I published it. When I tested the Web API with the default Xamarin.Forms app, the server returned an exception (500 Internal Server Exception) with the message "An error has occured.". After that I tried to enabled server log, remote debug and xml log files, but I didn't find much.

The remote debug showed that nothing was wrong with the "visible" backend code (no exception was thrown when debugging). The xml log files showed a Warning in an OWIN method, but no errors. The server log showed two errors in GET requests: azure-log.txt
Obs. I removed my app service name and replaced with "{servicename}".

I already tried to delete and re-create all Azure services, already tried to change from http to https and tried to change the connectionString to other values. But I did these changes only after trying to debug the default projects without any success.

I'm trying to solve this error for a while and I don't know anything more that I could do.
Thanks for the help!

2

2 Answers

2
votes

Exception=System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) ---> System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified at System.Data.ProviderBase.DbConnectionPool.TryGetConnection

According to the errors you provided, I assumed that you are using local database in your Azure mobile backend. You could leverage KUDU or Azure App Service Editor to check your MS_TableConnectionString connectionstring under your web.config file. The connectionstring would look like this:

<add name="MS_TableConnectionString" connectionString="Server=tcp:{your_dbservername}.database.windows.net,1433;Initial Catalog={your_dbname};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient"/>

When deploy your mobile app to Azure via Visual Studio, you need to point your connectionstring to your Azure db as follows:

For more details about creating and deploying your mobile app to Azure App Service, you could refer to this document. Also, you could leverage "All Settings > Application settings" under your web app blade to configure your connectionstring, which could override your existing connectionstring in your web.config file at runtime. For more details, you could follow this official tutorial.

Additionally, you could follow Adrian Hall's book here for a better understanding and a quick start with Azure Mobile Apps.

1
votes

The error was happening because the default project that Azure creates for the back-end is intended to be used with SQL. As I was using Azure Storage as db, I had to modify this project.

The chapter 3 of Adrian Hall's book (NoSQL Storage with the StorageDomainManager) explains exactly how to do that.