Error: SSL Connection error in MySQL using C# Asp.Net 6
Hello Guys, I have created a Console Application in Asp.Net 6. I will get data from a Redis message queue and insert all data into the MySql database. I get top of 100 records for each request.
I'm using MySqlHelper
library to help code and execute faster. Like this:
public async Task<int> MultipleInserBook(List<BookInfoEntities> books)
{
try
{
if (books == null || !books.Any()) return 0;
int countRecod = 0;
StringBuilder buildSql = new StringBuilder();
buildSql.Append("INSERT INTO tbltoken_spamblacklist(bookname, author, price, totalBook, createddate, status) VALUES ");
foreach (var book in books)
{
buildSql.AppendFormat("('{0}', '{1}', {2}, {3}, {4}, {5})", book.bookname, token.author, token.price, token.totalBook, Utils.DateTimeToUnix(DateTime.Now), 1);
countRecod++;
if (countRecod >= 1 && countRecod < books.Count) {
buildSql.Append(",");
}
}
string connectionString = MySqlConnectorHelper.GetConnectionString(ConnectionEntity.DBPosition.Default);
return await MySql.Data.MySqlClient.MySqlHelper.ExecuteNonQueryAsync(connectionString, buildSql.ToString());
}
catch (Exception ex)
{
throw ex;
}
}
It works very well in local Windows 11 but when I deploy it on Ubuntu 20.04. I get an exception SSL Connection error. ---> System.AggregateException: One or more errors occurred. ---> System.IO.IOException: The handshake failed due to an unexpected packet format.
MySql.Data.MySqlClient.MySqlException (0x80004005): SSL Connection error. ---> System.AggregateException: One or more errors occurred. ---> System.IO.IOException: The handshake failed due to an unexpected packet format.
at System.Net.Security.SslStream.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
at System.Net.Security.SslStream.PartialFrameCallback(AsyncProtocolRequest asyncRequest)
--- End of stack trace from previous location where exception was thrown ---
at System.Net.Security.SslStream.ThrowIfExceptional()
at System.Net.Security.SslStream.InternalEndProcessAuthentication(LazyAsyncResult lazyResult)
at System.Net.Security.SslStream.EndProcessAuthentication(IAsyncResult result)
at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult)
at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__64_2(IAsyncResult iar)
at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`1 promise, Boolean requiresSynchronization)
Have a problem with SSL, but I don't know why it used SSL for what. Because my code does not uses anything that requires the SSL.
I use MySql version 8 and ubuntu 20.04.
Thanks in advance.
- D1
DUANGPATHUM JOSUKE May 12 2022
I think your server doesn't support SSL, you can use
SSL Mode
option set toNone
in your connection string.For an example:
Data Source=127.0.0.1;Database=BookManager;User Id=root;Password=111111;encrypt=true;SSL Mode=None
It really worked for me.
- P0
Peter Melling May 12 2022
I remember I got the same error. I used
MySqlBulkCopy
package to help bulk insert many records at the same time. But I remove the function and forgot to remove that package. And then I removed it and the bug was solved.So I suggest you need to review all your packages again. Remove any package if your app doesn't use it.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.