I have Postgres running on Docker, I'm trying to update the DB with EntityFramework and I get an error in the Package Manager Console: Failed to connect to 172.17.0.2:5432. The postgres was created directly in Docker Desktop app.
PM> Update-Database
Build started...
Build succeeded.
Npgsql.NpgsqlException (0x80004005): Failed to connect to 172.17.0.2:5432
---> System.TimeoutException: Timeout during connection attempt
at Npgsql.Internal.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
at Npgsql.Internal.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
at Npgsql.Internal.NpgsqlConnector.RawOpen(SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt)
at Npgsql.Internal.NpgsqlConnector.<Open>g__OpenCore|208_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt)
at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.UnpooledDataSource.Get(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|45_0(Boolean async, CancellationToken cancellationToken)
at Npgsql.NpgsqlConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternal(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken)
at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Failed to connect to 172.17.0.2:5432
Program.cs
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("AppDbConnection")));
Connection string in appsettings.json
"ConnectionStrings": {
"AppDbConnection": "Host=172.17.0.2; Port=5432; Database=MyNewDb; Username=postgres; Password=postgrespw;"
}
I checked on what ip and port the container is running:
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f9b7485b6473 dpage/pgadmin4 "/entrypoint.sh" 59 minutes ago Up 58 minutes 443/tcp, 0.0.0.0:5050->80/tcp pgadmin4
f1422d67616e postgres:latest "docker-entrypoint.s…" About an hour ago Up About an hour 0.0.0.0:49153->5432/tcp postgres-O7pV
❯ docker inspect f1422 | grep IPAddress
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
❯ docker network ls
NETWORK ID NAME DRIVER SCOPE
5a77b8e238bc bridge bridge local
aae4971464e6 host host local
59c3a23f98d4 none null local
Related
When I use Sikuli in C# Selenium I am getting below error
System.Net.WebException : No connection could be made because the target machine actively refused it. [::1]:8080 (localhost:8080)
----> System.Net.Http.HttpRequestException : No connection could be made because the target machine actively refused it. [::1]:8080 (localhost:8080)
----> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException : No connection could be made because the target machine actively refused it. [::1]:8080
Stack Trace:
HttpWebRequest.GetResponse()
Screen.MakeRequest(String requestURLExtension, String jsonObject)
Screen.Find(Pattern pattern, Boolean highlight)
Login.StartBrowser() line 57
--HttpRequestException
HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.AddHttp11ConnectionAsync(HttpRequestMessage request)
TaskCompletionSourceWithCancellation`1.WaitWithCancellation(CancellationToken cancellationToken)
<12 more frames...>
Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
Socket.Connect(EndPoint remoteEP)
Socket.Connect(IPAddress[] addresses, Int32 port)
--- End of stack trace from previous location ---
Socket.Connect(IPAddress[] addresses, Int32 port)
Socket.Connect(String host, Int32 port)
Socket.Connect(EndPoint remoteEP)
<<CreateHttpClient>b__1>d.MoveNext()
--- End of stack trace from previous location ---
HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
Standard Output:
--Log for this test run can be found at: C:\Users\Sreeram.Potti\OneDrive - EY\Documents\Development\Automation\automation\kimautomation\bin\Debug\net6.0\Sikuli4Net.Client.Logs\log.29-11-20221252.txt--
:::Making Request to Service: http://localhost:8080/sikuli/api/find POST: {"jPattern":{"imagePath":"C:\\Logo\\Logo.jpg","offset_x":0,"offset_y":0,"similar":0.7},"highlight":false}:::
(result has additional output)
This is the code I am used to test. If I remove "s.Click(slogo)" from the code, then it is working fine. But I need to click and confirm the image.
Screen s = new Screen();
Pattern slogo = new Pattern("C:\\Logo\\Logo.jpg");
s.Click(slogo);
This is the package details
enter image description here
I want to check the exact image only loaded or not.
I can't connect my C# application to SQL database using mobile data.
If I try to connect to DB using my home Wi-Fi, it works normally.
When I try, I get this error:
MySqlConnector.MySqlException (0x80004005): Connect Timeout expired. ---> MySqlConnector.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
at MySqlConnector.Core.ServerSession.ConnectAsync (MySqlConnector.Core.ConnectionSettings cs, MySqlConnector.MySqlConnection connection, System.Int32 startTickCount, MySqlConnector.Core.ILoadBalancer loadBalancer, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x002fb] in /_/src/MySqlConnector/Core/ServerSession.cs:437
at MySqlConnector.Core.ConnectionPool.ConnectSessionAsync (MySqlConnector.MySqlConnection connection, System.String logMessage, System.Int32 startTickCount, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x000bc] in /_/src/MySqlConnector/Core/ConnectionPool.cs:367
at MySqlConnector.Core.ConnectionPool.GetSessionAsync (MySqlConnector.MySqlConnection connection, System.Int32 startTickCount, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x00519] in /_/src/MySqlConnector/Core/ConnectionPool.cs:94
at MySqlConnector.Core.ConnectionPool.GetSessionAsync (MySqlConnector.MySqlConnection connection, System.Int32 startTickCount, MySqlConnector.Protocol.Serialization.IOBehavior ioBehavior, System.Threading.CancellationToken cancellationToken) [0x00767] in /_/src/MySqlConnector/Core/ConnectionPool.cs:124
at System.Threading.Tasks.ValueTask`1[TResult].get_Result () [0x0001b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813
at MySqlConnector.MySqlConnection.CreateSessionAsync (MySqlConnector.Core.ConnectionPool pool, System.Int32 startTickCount, System.Nullable`1[T] ioBehavior, System.Threading.CancellationToken cancellationToken) [0x00120] in /_/src/MySqlConnector/MySqlConnection.cs:919
at MySqlConnector.MySqlConnection.CreateSessionAsync (MySqlConnector.Core.ConnectionPool pool, System.Int32 startTickCount, System.Nullable`1[T] ioBehavior, System.Threading.CancellationToken cancellationToken) [0x002f6] in /_/src/MySqlConnector/MySqlConnection.cs:941
at System.Threading.Tasks.ValueTask`1[TResult].get_Result () [0x0001b] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/Common/src/CoreLib/System/Threading/Tasks/ValueTask.cs:813
at MySqlConnector.MySqlConnection.OpenAsync (System.Nullable`1[T] ioBehavior, System.Threading.CancellationToken cancellationToken) [0x001c7] in /_/src/MySqlConnector/MySqlConnection.cs:425
at MySqlConnector.MySqlConnection.Open () [0x00000] in /_/src/MySqlConnector/MySqlConnection.cs:373
And this is my Server string:
"Server=xxx;Port=3306;Database=xxx;Uid=xxx;Password=xxx.;Convert Zero Datetime=True;"
Why I can connect to my DB only using Wi-Fi connection and not using mobile data?
SOLUTION: set the outbound of group security as 0.0.0.0/0
I'm using Amazon RDS as host.
The solution was edit the outbound role of db group security and set the IP: 0.0.0.0/0 in order to accept all IP.
I am trying to make tests running parallel on my local machine without using selenium grid. My problem is with Firefox driver. I have two tests on the same website. When I execute below code for FirefoxDriver one test is abadoned and I have timeout error. When I am executing using ChromeDriver or EdgeDriver there is no issue.
[Binding]
public class Hooks
{
public IWebDriver driver;
private IObjectContainer objectContainer;
public Hooks(IObjectContainer objectContainer)
{
this.objectContainer = objectContainer;
}
[BeforeScenario]
public void BeforeScenario()
{
driver = new FirefoxDriver(AppDomain.CurrentDomain.BaseDirectory);
objectContainer.RegisterInstanceAs(driver);
}
[AfterScenario]
public void AfterScenario()
{
driver.Close();
}
Scope of parallelism is set to [assembly: Parallelizable(ParallelScope.Fixtures)]
Error:
Message:
OpenQA.Selenium.WebDriverException : The HTTP request to the remote WebDriver server for URL http://localhost:55285/session timed out after 60 seconds.
----> System.Threading.Tasks.TaskCanceledException : The request was canceled due to the configured HttpClient.Timeout of 60 seconds elapsing.
----> System.TimeoutException : The operation was canceled.
----> System.Threading.Tasks.TaskCanceledException : The operation was canceled.
----> System.IO.IOException : Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
----> System.Net.Sockets.SocketException : The I/O operation has been aborted because of either a thread exit or an application request.
Stack Trace:
HttpCommandExecutor.Execute(Command commandToExecute)
DriverServiceCommandExecutor.Execute(Command commandToExecute)
WebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
WebDriver.StartSession(ICapabilities desiredCapabilities)
WebDriver.ctor(ICommandExecutor executor, ICapabilities capabilities)
FirefoxDriver.ctor(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
FirefoxDriver.ctor(String geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout)
FirefoxDriver.ctor(String geckoDriverDirectory, FirefoxOptions options)
FirefoxDriver.ctor(String geckoDriverDirectory)
Hooks.BeforeScenario() line 57
BindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
SafeBindingInvoker.InvokeBinding(IBinding binding, IContextManager contextManager, Object[] arguments, ITestTracer testTracer, TimeSpan& duration)
TestExecutionEngine.OnAfterLastStep()
TestRunner.CollectScenarioErrors()
LoginFeature.ScenarioCleanup()
LoginFeature.StandardUserIsAbleToLogIn() line 9
--TaskCanceledException
HttpClient.HandleFailure(Exception e, Boolean telemetryStarted, HttpResponseMessage response, CancellationTokenSource cts, CancellationToken cancellationToken, CancellationTokenSource pendingRequestsCts)
HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
HttpCommandExecutor.Execute(Command commandToExecute)
--TimeoutException
--TaskCanceledException
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken)
--IOException
AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
Int32>.GetResult(Int16 token)
HttpConnection.InitialFillAsync(Boolean async)
HttpConnection.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
--SocketException
Standard Output:
-> error: The HTTP request to the remote WebDriver server for URL http://localhost:55285/session timed out after 60 seconds. (62,2s)
Given website is opened
-> skipped because of previous errors
When user provides credentials
-> skipped because of previous errors
Then is successfuly logged in
-> skipped because of previous errors
-> error: Object reference not set to an instance of an object. (0,0s)
Does anyone have any suggestions/ ideas why this is happening?
After reinstalling the drivers and PC restart everything started working. I forgot about this fundamental rule to turn on and off :)
I'm running ChromeDriver (v89) & Selenium 4.1 on MacOS and am getting an exception when instantiating ChromeDriver by passing an instance of ChromeDriverService and these options:
{
"browserName": "chrome",
"goog:chromeOptions": {
"args": [
"no-sandbox"
],
"debuggerAddress": "127.0.0.1:8080"
}
}
Details of the exception:
OpenQA.Selenium.WebDriverException: The HTTP request to the remote WebDriver server for URL http://localhost:49385/session timed out after 60 seconds.
---> System.Threading.Tasks.TaskCanceledException: The operation was canceled.
---> System.IO.IOException: Unable to read data from the transport connection: Operation canceled.
---> System.Net.Sockets.SocketException (89): Operation canceled
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.GetResult(Int16 token)
at System.Net.Http.HttpConnection.FillAsync()
at System.Net.Http.HttpConnection.ReadNextResponseHeaderLineAsync(Boolean foldedHeadersAllowed)
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
--- End of inner exception stack trace ---
at System.Net.Http.HttpConnection.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithNtConnectionAuthAsync(HttpConnection connection, HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo) at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) --- End of inner exception stack trace --- at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) at OpenQA.Selenium.WebDriver.Execute(String driverCommandToExecute, Dictionary2 parameters)
at OpenQA.Selenium.WebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.WebDriver..ctor(ICommandExecutor executor, ICapabilities capabilities)
at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options)
The same code worked fine on Windows, so I dare to say that it's been tested.
Libraries I'm using:
OpenQA,/Users/mbaas/.nuget/packages/Selenium.WebDriver/4.1.0/lib/netstandard2.1/WebDriver.dll
OpenQA.Selenium,/Users/mbaas/.nuget/packages/Selenium.WebDriver/4.1.0/lib/netstandard2.1/WebDriver.dll
OpenQA.Selenium.Chrome,/Users/mbaas/.nuget/packages/Selenium.WebDriver/4.1.0/lib/netstandard2.1/WebDriver.dll
Newtonsoft.Json,/Users/mbaas/.nuget/packages/Newtonsoft.Json/12.0.3/lib/netstandard2.0/Newtonsoft.Json.dll
OpenQA.Selenium.Support,/Users/mbaas/.nuget/packages/Selenium.Support/4.1.0/lib/netstandard2.1/WebDriver.Support.dll
OpenQA.Selenium.Support.UI,/Users/mbaas/.nuget/packages/Selenium.Support/4.1.0/lib/netstandard2.1/WebDriver.Support.dll
I think I found the answer: the plan was to launch a separate process beforehand that runs CEF and the site - but that step failed, so there is no browser it could talk to.
My bad - I should have checked that before posting here.
I just set up a LAMP server VM on Digital Ocean. OS is Ubuntu 18.04 x64. MySQL is 5.7.23. I also have a published to a local folder asp.net core web application, which I have set to Ubuntu 18.04-x64. I copied the files from the local folder to var/MyApp on the server and set chmod +x on the executable file. I also changed the MySql root password and created a database named limboworld. My application is set to run all migrations on startup. However when I start it with ./catchme.bg I get the following output with an error shown below.
I tried changing the MySql password and also the connection string from:
"catchmebgContextConnection": "Server=localhost;Database=limboworld;User=root;Password=limboworld;"
to
"catchmebgContextConnection": "Server=localhost;Database=limboworld;Uid=root;Pwd=limboworld;"
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/root/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.1.11-servicing-32099 initialized 'catchmebgContext' using provider 'Pomelo.EntityFrameworkCore.MySql' with options: MaxPoolSize=128 ServerVersion 5.7.24 MySql
fail: Microsoft.EntityFrameworkCore.Database.Connection[20004]
An error occurred using the connection to database '' on server 'localhost'.
MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user 'root'#'localhost'
...
Application startup exception: MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user 'root'#'localhost'
at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 356
at MySql.Data.MySqlClient.MySqlConnection.CreateSessionAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 442
at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 175
at MySql.Data.MySqlClient.MySqlConnection.Open() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 161
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func`2 operation, Func`2 verifySucceeded, TState state)
at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlDatabaseCreator.Exists(Boolean retryOnNotExists)
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at catchme.bg.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, catchmebgContext db1, CatchmeContext db2) in C:\Users\Ivan\Source\repos\catchme.bg\catchme.bg\catchme.bg\Startup.cs:line 84
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
crit: Microsoft.AspNetCore.Hosting.Internal.WebHost[6]
Application startup exception
MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user 'root'#'localhost'
at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 356
at MySql.Data.MySqlClient.MySqlConnection.CreateSessionAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 442
at MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 175
at MySql.Data.MySqlClient.MySqlConnection.Open() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs:line 161
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlDatabaseCreator.<>c__DisplayClass18_0.<Exists>b__0(DateTime giveUp)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.<>c__DisplayClass12_0`2.<Execute>b__0(DbContext c, TState s)
at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.ExecutionStrategyExtensions.Execute[TState,TResult](IExecutionStrategy strategy, Func`2 operation, Func`2 verifySucceeded, TState state)
at Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlDatabaseCreator.Exists(Boolean retryOnNotExists)
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at catchme.bg.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, catchmebgContext db1, CatchmeContext db2) in C:\Users\Ivan\Source\repos\catchme.bg\catchme.bg\catchme.bg\Startup.cs:line 84
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.Configure(IApplicationBuilder app)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Hosting environment: Production
Content root path: /var/MyApp
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
I would like to connect to the database on application startup and run the migrations. However because of the above error it doesn't work.
Any ideas would be very helpful!
It turned out MySql 5.7 uses a plugin named 'auth_socket', which enables the root user to login to mysql with no password.
This line sets a password 'test' for the root account:
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'test';
After setting the password in the appsettings.json and appsettings.production.json files, everything worked correctly!
Here is the link, that I used to fix the problem:
https://www.percona.com/blog/2016/03/16/change-user-password-in-mysql-5-7-with-plugin-auth_socket/
Thank you all for looking at my question!