0

I've been trying to deploy an ASP.NET Boilerplate application to Azure for the last couple of days and I haven't been able to do so. I keep stumbling upon this error:

The error on the app .azurewebsites domain

First I make a Web App + SQL resource and then publish my project to it from inside Visual Studio using the right click -> deploy option, and then importing the publication profile I got from Azure. I make sure the database connection string in the appsettings.production.json are correct but I can't seem to connect to the database. If I try to connect to the database through the SQL Server Management Studio I get a similar error. This means something is wrong with the database itself.

Do I need to create a separate SQL database in Azure that makes use of the SQL database server that comes with the Web App + MySQL resource?

Any help would be greatly appreciated! I have been spending way too much time on this problem already.

This is a screenshot of all the resources in the Azure portal, these were created while creating the Web app + MySQL resource:

Azure portal resources

Edit: This is the error I am getting:

Win32Exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. Unknown location SqlException: 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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.) Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e) InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseSqlServer' call. Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute<TState, TResult>(TState state, Func<DbContext, TState, TResult> operation, Func<DbContext, TState, ExecutionResult<TResult>> verifySucceeded) Win32Exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

Jobje325
  • 55
  • 12
  • 1
    how did you create mysql db? could you post some images of azure UI showing your db resources – Yehor Androsov Oct 25 '20 at 19:04
  • @YegorAndrosov Thanks for your reply! I added an image of the resources in my post above since I can't post them in a comment. I haven't changed anything to these yet – Jobje325 Oct 25 '20 at 20:54
  • Do you need more screenshots or will these suffice? @YegorAndrosov – Jobje325 Oct 27 '20 at 08:41
  • @Jobje325 post the error *text*, not screenshots. Screenshots can't be googled, copied or compiled. The error is a *SQL Server* error too. If you search for it you'll find there are a lot of similar SO questions. If you tried to use a SQL Server connection string to connect to MySQL, the connection will fail – Panagiotis Kanavos Oct 27 '20 at 10:03
  • Does this answer your question? [MySQL "network-related or instance-specific error occurred while establishing a connection to SQL Server"](https://stackoverflow.com/questions/21446615/mysql-network-related-or-instance-specific-error-occurred-while-establishing-a) – Panagiotis Kanavos Oct 27 '20 at 10:04
  • you are using SQL Server provider, not MySQL – Yehor Androsov Oct 27 '20 at 18:03
  • @YegorAndrosov Thank you for this comment, I only just now realized my stupidity that has cost me countless hours. In azure I selected Web App + MySQL instead of Web App + SQL. This didn't give me a database but a database server. – Jobje325 Oct 27 '20 at 18:09
  • Glad you resolved it :D – Yehor Androsov Oct 27 '20 at 18:34

2 Answers2

1

Since you mentioned you can't access db in any other way, I provided step-by-step instruction

You can get your connection string from Azure resource panel

enter image description here

Navigate to Connection security tab and enable access from other Azure resources. This way WebApp will be able access database server inside Azure network. I also added my client IP to test db connection from my PC later. Click Save at the top when you are done

enter image description here

On the same page there is setting called configure SSL connection. Certificate can be downloaded from https://learn.microsoft.com/uk-ua/azure/mysql/howto-configure-ssl. I used this file https://www.digicert.com/CACerts/BaltimoreCyberTrustRoot.crt.pem . Optionally, you could disable this feature for now.

enter image description here

Now we have everything to test db connection. I will show it with the use of HeidiSQL client.

enter image description here enter image description here

Click open and see your databases

enter image description here

According to this you need to have CACertificateFile parameter appended to connection string to use SSL, so you need to put file into repository and provide its relative path in connection string

Yehor Androsov
  • 4,885
  • 2
  • 23
  • 40
  • thanks for the reply! I chose to disable the SSL for now and managed to connect to the database using HeidiSQL with my credentials. Whenever I enter these in SQL management studio or my appsettings.production.json file on the server I still get the same error. I added the error in text to my initial post above here. – Jobje325 Oct 27 '20 at 17:55
0

This was all caused by a stupid mistake, in the Azure portal I selected the Web App + MySQL resource instead of the Web App + SQL resource. For the ASP.NET Boilerplate project I am using you need a Web App + SQL resource.

Jobje325
  • 55
  • 12