Problem:
This article introduces the use of SqlConnection to connect to MySQL, but I encountered mistake. SqlConnection is used to connect to SQL Server. A special connector is required to connect to MySQL.
Problem description:
The sample code provided uses SqlConnection to connect to MySQL, but the following error was encountered:
System.ArgumentException: Keyword not supported: 'driver'.
Problem Solution :
To connect to MySQL, you need to use MySqlConnection class, not SqlConnection. MySqlConnector is a community-developed and maintained .NET connector for connecting to MySQL.
Solution:
MySqlConnection connection = new MySqlConnection(connectionString);
MySqlCommand command = new MySqlCommand(query, connection);
Connection string example:
"Server=localhost;Database=my_database;Uid=my_user;Pwd=my_password"
Please note that you need to provide the correct connection string, including Host, database, username and password.
The above is the detailed content of Why Doesn\'t SqlConnection Work with MySQL, and How Can I Fix It?. For more information, please follow other related articles on the PHP Chinese website!