Unable to connect to any of the specified MySQL hosts during ASP.net Azure deployment

3

In my ASP.net Web App, I built a MySQL database using MySQL workbench and connected it to Azure through "Azure for MySQL Database" resource group. The following is the connection string of the database written in Web.config


<add name ="AzureCon" connectionString="Server={myserver}; Port=3306; Database={mydatabase}; Uid={myuser}; Pwd={mypassword}; SslMode=Preferred;"/>

I call the connection string using the following code


string CoString = ConfigurationManager.ConnectionStrings["AzureCon"].ConnectionString;

However, when I publish the web app using Azure, the only error I get is:

Unable to connect to any of the specified MySQL hosts

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: MySqlConnector.MySqlException: Unable to connect to any of the specified MySQL hosts.

Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.]
   MySqlConnector.Core.<ConnectAsync>d__68.MoveNext() +1567
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) +26
   MySqlConnector.Core.<GetSessionAsync>d__10.MoveNext() +2632
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +27
   MySqlConnector.Core.<GetSessionAsync>d__10.MoveNext() +3745
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   System.Threading.Tasks.ValueTask`1.get_Result() +121
   MySqlConnector.<CreateSessionAsync>d__115.MoveNext() +696
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   MySqlConnector.<OpenAsync>d__27.MoveNext() +977
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   MySqlConnector.MySqlConnection.Open() +61
   Hangfire.MySql.MySqlStorage.CreateAndOpenConnection() +49
   Hangfire.MySql.MySqlStorage..ctor(String connectionString, MySqlStorageOptions storageOptions) +140
   CoPro.<GetHangfireServers>d__9.MoveNext() in C:\Users\smir\Desktop\Files and Folders\Programming\C#\CoPro\CoPro\Startup.cs:22
   System.Linq.Buffer`1..ctor(IEnumerable`1 source) +217
   System.Linq.Enumerable.ToArray(IEnumerable`1 source) +76
   Hangfire.HangfireAspNet.StartInstances(Func`1 configuration) +130
   Hangfire.HangfireAspNet.Use(Func`1 configuration) +13
   Hangfire.HangfireAspNet.UseHangfireAspNet(IAppBuilder builder, Func`1 configuration) +21
   CoPro.Startup.Configuration(IAppBuilder app) in C:\Users\smir\Desktop\Files and Folders\Programming\C#\CoPro\CoPro\Startup.cs:37

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +168
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +105
   Owin.Loader.<>c__DisplayClass19_1.<MakeDelegate>b__0(IAppBuilder builder) +66
   Owin.Loader.<>c__DisplayClass9_0.<LoadImplementation>b__0(IAppBuilder builder) +123
   Microsoft.Owin.Host.SystemWeb.<>c__DisplayClass5_0.<InitializeBlueprint>b__0(IAppBuilder builder) +81
   Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup) +445
   Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action`1 startup) +40
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +70
   System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +119
   Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +91
   System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +522
   System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +176
   System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +219
   System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +304

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +659
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +89
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +189  

I'm using no other database or connection.

As in Azure resource group, I have updated the Firewall security and added the "allow all" rule for all IPv4 addresses.

MySQL works fine locally.

Here's my firewall settings in the Azure Database for MySQL server

enter image description here

enter image description here

Here's the "Users and Privileges" tab in my connection in MySQL Workbench

enter image description here

Note: The problem was there even before connecting MySQL to Azure

c#
mysql
asp.net
.net
azure
asked on Stack Overflow Sep 9, 2020 by (unknown user) • edited Sep 11, 2020 by (unknown user)

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0