简体   繁体   中英

Error while connecting from another device on the network,using Pomelo.EntityFrameworkCore.MySql v6

MySqlConnector.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
   at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, MySqlConnection connection, Int32 startTickCount, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 433
   at MySqlConnector.Core.ConnectionPool.ConnectSessionAsync(MySqlConnection connection, String logMessage, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 363
   at MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 94
   at MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, Int32 startTickCount, IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ConnectionPool.cs:line 124
   at MySqlConnector.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Int32 startTickCount, Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 915
   at MySqlConnector.MySqlConnection.OpenAsync(Nullable`1 ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlConnection.cs:line 406
   at MySqlConnector.MySqlConnection.Open() in /_/src/MySqlConnector/MySqlConnection.cs:line 369
   at Microsoft.EntityFrameworkCore.ServerVersion.AutoDetect(String connectionString)
   at MadaSoft.AddDbContextHostBuilderExtensions.<>c__DisplayClass1_0.<GetMySql>b__0(DbContextOptionsBuilder o) in D:\VS Projects\MadaProject\MadaSoft\HostBuilder\AddDbContextHostBuilderExtensions.cs:line 32
   at MadaSoft.ContextFactoryApp.CreateDbContext() in D:\VS Projects\MadaProject\MadaSoft\_DbContext\ContextFactoryApp.cs:line 19
   at MadaSoft.App.MigrateContextApp() in D:\VS Projects\MadaProject\MadaSoft\App.xaml.cs:line 63
   at MadaSoft.App.OnStartupTask() in D:\VS Projects\MadaProject\MadaSoft\App.xaml.cs:line 55
   at MadaSoft.App.OnStartup(StartupEventArgs e) in D:\VS Projects\MadaProject\MadaSoft\App.xaml.cs:line 35

You register the service as follows

            Action<DbContextOptionsBuilder> configureDbContext = o =>
            {
                o.UseMySql(connectionString,ServerVersion.AutoDetect(connectionString));
                o.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
            }; 

            services.AddDbContext<ContextApp>(configureDbContext);
            services.AddSingleton(new ContextFactoryApp(configureDbContext));

When connecting from the same computer, the connection is correct.. but when connecting from another computer, the problem appears

This is the connection string server=localhost; Port=3306; Database=dbName; Uid=root; Pwd=root; sslmode=none; CharSet=utf8;

Thanks stackoverflow members.. I tried until I found the answer.. the error was due to using the default user (root).. I created a new user in the database engine, and gave it permissions.. and >>>> OK >>> problem was fixed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM