I am working on Blazor Server-Side project that needs to run in an Ubuntu Linux 18.04LTS server. (NOTE: This project is not using Web Assembly.)
I am using C# and the Pomelo.EntityFrameWorkCode.MySql nuget package (v3.1.1) to connect to a MySQL database running on the Linux server.
When I run the app locally on my Windows development system, everything works correctly. When I publish the files to the Linux server, it works about 5% of the time - the remainder I get an error message
Pomelo MySqlException: Unable to connect to any of the specified MySQL hosts
I am connecting to the same MySQL database on both my Windows system and the Linux server. The MySQL is running on Linux, correct ports are open, etc.
More detailed error message is:
An unhandled exception occurred while processing the request.
MySqlException: Unable to connect to any of the specified MySQL hosts.
MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs, line 442
InvalidOperationException: An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySql' call.
Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute(TState state, Func operation, Func> verifySucceeded)
MySqlException: Unable to connect to any of the specified MySQL hosts.
MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in
C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs
MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, IOBehavior ioBehavior, CancellationToken cancellationToken) in > C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs
MySqlConnector.Core.ConnectionPool.GetSessionAsync(MySqlConnection connection, IOBehavior ioBehavior, CancellationToken cancellationToken) in > C:\projects\mysqlconnector\src\MySqlConnector\Core\ConnectionPool.cs
System.Threading.Tasks.ValueTask.get_Result()
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable+ConfiguredValueTaskAwaiter.GetResult()
MySql.Data.MySqlClient.MySqlConnection.CreateSessionAsync(ConnectionPool pool, Nullable ioBehavior, CancellationToken cancellationToken) in
C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs
System.Threading.Tasks.ValueTask.get_Result()
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable+ConfiguredValueTaskAwaiter.GetResult()
MySql.Data.MySqlClient.MySqlConnection.OpenAsync(Nullable ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs
MySql.Data.MySqlClient.MySqlConnection.Open() in C:\projects\mysqlconnector\src\MySqlConnector\MySql.Data.MySqlClient\MySqlConnection.cs
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(bool errorsExpected)
Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(bool errorsExpected)
Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlRelationalConnection.Open(bool errorsExpected)
Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject)
Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable+Enumerator.InitializeReader(DbContext _, bool result)
Pomelo.EntityFrameworkCore.MySql.Storage.Internal.MySqlExecutionStrategy.Execute(TState state, Func operation, Func> verifySucceeded)
The Configuration in the Startup class looks like:
services.AddDbContext<LabDataDbContext>(options => {
options.UseMySql(Configuration.GetConnectionString("LabDbConnection"));
options.EnableDetailedErrors();
});
My Connection String is:
"server=server.grafton.internal;port=3306;database=labdb;user=******;password=******;charset=utf8"
The interesting thing is I can use MySQL Workbench and connect to the database from either my Windows dev system, or the Linux server using exactly the same credentials.
This application is designed to be run in house only and the server running the app is not visible on the Internet, so I am not too concerned about security issues (if someone wants to know what a bunch of autistic kids have as equipment and activities, they can have it!!)
While trying to isolate the error, I have completely removed and redeployed the app to a different linux server on the network with the same result, but as I have stated earlier, about 5% of the time, the app works as expected on the linux server.
Other pages in the app that do NOT use a database are working correctly, so I do not think it is an issue with the web server (NGinx as a reverse proxy to Kestrel).
I also want to stress that the app works about 5% of the time running on linux, and 100% of the time running on Windows - both connecting to the same MySQL server running on linux.
If more code samples are wanted, the app is on Github at https://github.com/SteveTeece/Lab.
This one has got me stumped. Any ideas on how to fix this and get it running on the Linux server is greatly appreciated.
Thanks
Thanks everyone for your feedback and comments.
After another few days of fiddling, I've resolved this issue by using
Server=localhost;
in the production connection string instead of the FQDN.
Related
Oh my, how do I even start asking this question.... I have a feeling this has been answered more than ones but I'm too dumb to understand the answers.... So I'm sure I'll be roasted for lots of reasons, but I'm feeling brave today.
I'm trying to automatically update my Database with a .csv file I receive daily.
Biggest issue I have is that I have no coding experience and my SQL is extremely limited so when I search for help regarding this issue I .... don't really know what to do with the information.
In order to get Power Automate (desktop) to connect to the server I had to install ODBC Data Sources to create a connection string. Then I tried a simple query to make sure i have connection, and this works fine.
Now, for the actual query I want to run;
"LOAD DATA LOCAL INFILE 'C:\Automation\Lagerførte Artikkler.csv' REPLACE INTO TABLE ......
I get this error;
Error in SQL statement ERROR [HY000] [MySQL][ODBC 8.0(w) Driver][mysqld-5.5.5-10.5.18-MariaDB-1:10.5.18+maria~ubu2004-log
LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.
Detailed Error;
ERROR [HY000] [MySQL][ODBC 8.0(w) Driver][mysqld-5.5.5-10.5.18-MariaDB-1:10.5.18+maria~ubu2004-log]LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.: Microsoft.Flow.RPA.Desktop.Modules.SDK.ActionException: Error in SQL statement ERROR [HY000] [MySQL][ODBC 8.0(w) Driver][mysqld-5.5.5-10.5.18-MariaDB-1:10.5.18+maria~ubu2004-log]LOAD DATA LOCAL INFILE file request rejected due to restrictions on access. ---> System.Data.Odbc.OdbcException: ERROR [HY000] [MySQL][ODBC 8.0(w) Driver][mysqld-5.5.5-10.5.18-MariaDB-1:10.5.18+maria~ubu2004-log]LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at Microsoft.Flow.RPA.Desktop.Modules.Database.Actions.DatabaseActions.ExecuteSQLStatement(Variant connectionString, Variant sqlConnectionVariable, Variant sqlCommand, Variant& result, Int32 timeout, Int32 getConnection)
--- End of inner exception stack trace ---
at Microsoft.Flow.RPA.Desktop.Modules.Database.Actions.ExecuteSqlStatement.Execute(ActionContext context)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ActionRunner.Run(IActionStatement statement, Dictionary`2 inputArguments, Dictionary`2 outputArguments)
If I change the path to something non existing I get same error.
If I run this query in HeidiSQL it works fine. Also tried to run it through SQL plugin for VS, and this also works fine. (The pathing then is C:\Users\UNRAID~1\DOCUME~1\AUTOMA~1\LAGERF~1.CSV)
If I delete the LOCAL part in the query I get this error;
Access denied for user 'cncportalenno01'#'%' (using password: YES)
What I don't understand is how this user has no access when it clearly has access when going through heidi or vs ? (This might be a dumb take, but as I said, I'm .... lost)
Any help, or guidance wound be greatly appreciated, spent 20h on this f... issue already.
Also tried to put the csv file in Public (Users) folder and just on C:
There is also this checkbox in ODBC Data source config which states "Enabled LOAD DATA LOCAL INFILE statements" but this is an option which do not save. How to overwrite this setting I have no clue.
ODBC Settings
I managed to get this bloddy thing fixed by using "MariaDB ODBC 3.1" Driver rather than "MySQL ODBC 8.0 Driver".....
Relief and anger at same time sure feels wierd.
The server needs local_infile=1 enabled. Given HeidiSQL worked we can assume this is set.
The second requirement is the client connection needs to connect with a local_infile flag set.
In ODBC, this is the OPTIONS with bit 7 set aka 128 (2^7).
I am working on a web application that is using AWS RDS (MySQL). Everything works fine until I send 10/20 concurrent requests. When I start sending more concurrent requests (say 100/200), then RDS does not respond in timely manner and application throws errors -
MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider._TrackEntities[TOut,TIn](IEnumerable`1 results, QueryContext queryContext, IList`1 entityTrackingInfos, IList`1 entityAccessors)+MoveNext()
at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
At the same time, if I go and check the RDS cluster or database monitoring, I do not see any spikes in CPU usage or abnormal connections.
Can you provide any hint as to what should I investigate further to identify the root cause?
[Update 31/10/2022 12:30 PM]
In the performance insights of the database, I can see a following graph that interests me:
I'm using mysql 5.7.31 with C# on Linux ubuntu
When I programmatically delete a large table or drop a database I get this timeout
Stack=MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered during command execution.
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Fatal error encountered attempting to read the resultset.
---> MySql.Data.MySqlClient.MySqlException (0x80004005): Reading from the stream has failed.
---> System.IO.IOException: Unable to read data from the transport connection: Connection timed out.
---> System.Net.Sockets.SocketException (110): Connection timed out
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count)
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.LoadPacket()
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
To fix this I've attempted
I added this to my connection string
Connect Timeout=60
I added this to my mysqld.cnf, Restarted and checked it show variables. The log file shows it timed-out after 42 seconds.
connect_timeout=60000
interactive_timeout=60000
wait_timeout=60000
I think the issue is "Unable to read data from the transport connection: Connection timed out."
But not sure which variable needs to be changed to fix this?
Thanks
connect_timeout is used only when the client and server are performing a handshake, during the initial client connection. Increasing this helps if the client gets errors like Lost connection to MySQL server.... The default is 10 seconds.
I've never had a reason to tune this variable, because if the client can't connect within 10 seconds, it's probably blocked by a firewall, or routing, or else the MySQL Server is simply not running or is listening on another port. Increasing the timeout will not help in these cases.
wait_timeout helps the client is idle for a long time between queries. The client is not considered idle if the query executes for a long time. The idle time starts when a query finishes. The default is 8 hours (28800 seconds). If your app is timing out during an SQL statement execution, then this variable is not relevant.
interactive_timeout is just like wait_timeout, but for "interactive" clients. The only client that is in this category is the mysql command-line client. You can ignore this timeout variable, unless you're working on the mysql CLI.
You might need to tune net_read_timeout or net_write_timeout. But I wouldn't expect either of these to be necessary.
Tip: Use XFS as the filesystem for the MySQL datadir on Linux. It's much faster to drop tables or schemas, regardless of how large they are. XFS gives better performance for other work too, not just dropping tables.
We recently split our single EC2 (t2.small) instance which was running (IIS and MySQL) into 2 - (t2.small) instances. We moved all the IIS logic to the new instance and updated the WebConfigs to connect to the old machine which is running MySQL. After firing everything up we noticed very random/sporadic exceptions from MySQL related to connection issues. Overall our connection to the DB works but it seems to drop under certain cases. We tried tweaking timeouts on both IIS and MySQL side but didn't help. The last thing we tried was instead of using the private (Internal) IP for the connection to the MySQL Db we used the public (Elastic IP). With the public IP everything works perfect and we do not get any connection exceptions
Does anyone have any insight into why using the private IP between the servers is inconsistent, but the public IP works very reliably?
MySQL Exception:
*MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution. ---> MySql.Data.MySqlClient.MySqlException: Fatal error encountered attempting to read the resultset. ---> MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed. ---> System.IO.IOException: Unable to read data from the transport connection: 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. ---> System.Net.Sockets.SocketException: 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 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) --- End of inner exception stack trace --- at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at MySql.Data.MySqlClient.TimedStream.Read(Byte[] buffer, Int32 offset, Int32 count) at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream, Byte[] buffer, Int32 offset, Int32 count) at MySql.Data.MySqlClient.MySqlStream.LoadPacket()*
*System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> MySql.Data.MySqlClient.MySqlException: Reading from the stream has failed. ---> System.IO.IOException: Unable to read data from the transport connection: 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. ---> System.Net.Sockets.SocketException: 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 at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)*
We ended up solving this issue by following this guide for windows. Setting the below TCP settings in the Registry.
https://docs.aws.amazon.com/redshift/latest/mgmt/connecting-firewall-guidance.html
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters\:
KeepAliveTime: 30000
KeepAliveInterval: 1000
TcpMaxDataRetransmissions: 10
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
We have a clan MySQL database that tracks player stats in a game. There person in charge of our MySQL is away at the moment and we are getting this following Error
[18:17:18 23] Error in Tablebuilder:
[18:17:18 23] Message: Unable to connect to any of the specified MySQL hosts.
[18:17:18 23] Native: -2147467259
[18:17:18 24] Source: MySql.Data
[18:17:18 24] StackTrace: at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.Driver.Open()
at MySql.Data.MySqlClient.Driver.Create(MySqlConnecti onStringBuilder settings)
at MySql.Data.MySqlClient.MySqlPool.GetPooledConnecti on()
at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver()
at MySql.Data.MySqlClient.MySqlPool.GetConnection()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at PRoConEvents.CChatGUIDStatsLoggerBF3.tablebuilder( )
[18:17:18 24] InnerException: System.Net.Sockets.SocketException: 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 50.63.244.184:3306
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at MySql.Data.Common.StreamCreator.CreateSocketStream (IPAddress ip, Boolean unix)
at MySql.Data.Common.StreamCreator.GetStreamFromHost( String pipeName, String hostName, UInt32 timeout)
at MySql.Data.Common.StreamCreator.GetStream(UInt32 timeout)
at MySql.Data.MySqlClient.NativeDriver.Open()
[18:17:18 24] Error: System.NullReferenceException: Object reference not set to an instance of an object.
at PRoConEvents.CChatGUIDStatsLoggerBF3.tablebuilder( )
Any ideas what the issue could be?
You should start by reading error messages. They look like gibberish but when you read closely, often there is a part it tells you what's going on.
[18:17:18 24] InnerException: System.Net.Sockets.SocketException:
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 50.63.244.184:3306
You should now:
Execute telnet localhost 3306 from the database server and if it fails, it's an issue with the DB server
Execute telnet 50.63.244.184 3306 from the application server and if it fails, it's an issue with the network
You have two exceptions, them tested, but the meaning is clear:
"Unable to connect to any of the specified MySQL hosts."
and
"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"
So in short: your webserver cannot connect to you database server. Your database server (the MySQL server process mysqld.exe or the server itself, like its OS, hardware, anything) might be stopped. Or the firewall was reset to block connections on the MySQL port 3306. It could be anything.
I assume you've got a standard webhost - ping them and ask them why your database server isn't operational.
...but before you embarrass yourself, make sure that your application is connecting to the right server (i.e. production DB, not dev or staging DB). Take a look at your connection string.