问题
I'm trying to open a connection to a MySql database using the following code piece:
string connectionString = "Server=ip_number;Database=database_name;Uid=uid;Password=password";
MySqlConnection connection;
connection = new MySqlConnection(connectionString);
connection.Open();
And here is the exception I get:
I'm using the latest mysql connector (downloaded from here). What am I missing?
Thanks in advance,
回答1:
May you try this:
Connection to server:
string connectionString= "datasource=localhost;port=3306;username=uid;password=1234"
Use the "MySqL-Methodes" to INSERT/UPDATE/SELECT... like:
public string pathselectDB = "select *from try.data;";
public string pathinsertDB = "INSERT INTO `try`.`data`";
string constrnig = pathtoDB;
string Query = pathinsertDB +"(`value1`, `value2`) values('"2"','3',');";
MySqlConnection conDataBase = new MySqlConnection(constrnig);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
MySqlDataReader myReader;
this is just an example... I hope this solved your problem.
You can set your username and password in the MySql-Editor! if you need help there just set a commend under this.
回答2:
Solution 1: If SSL is not required. Since it is caused by SSL, we can turn off SSL by appending "SslMode=None" to the connection string.
Solution 2: If SSL is required, server identity is important and needs to be verified. The server needs a internet connection to do the cert verification. Please note the crypto API doesn't update CTL for every process. The CTL is maintained at operating system level. Once you connect the server to internet and make an SSL database connection to the server, the CTL will be updated automatically. Then you may disconnect the internet connection. Note again the CTL has its expiration date and after that the Windows needs to update it again. This will occur probably after several months.
Solution 3: If SSL is required but the server identity is not important. Typically SSL is only used to encrypt the network transport in this case. We can turn off CTL update:
- Press Win+R to open the "Run" dialog Type "gpedit.msc" (without quotes) and press Enter In the "Local Group Policy Editor", expand "Computer Configuration", expand "Administrative Templates", expand "System", expand "Internet Communication Management", and then click "Internet Communication settings". In the details panel, double-click "Turn off Automatic Root Certificates Update", click Enabled, then click OK. This change will be effective immediately without restart.
https://blog.csdn.net/fancyf/article/details/78295964 Clearly explains the root cause and solution.
来源:https://stackoverflow.com/questions/26652833/reading-from-the-stream-has-failed-mysqlexception