When using SqlConnection to connect to the MySQL database in an ASP.NET application, you may encounter "Keyword not supported: 'driver '"mistake. This is because SqlConnection is specifically designed to connect to SQL Server, while MySQL requires the use of a specific MySQL connector.
In order to solve this problem, you need to perform the following steps:
MySqlConnection connection = new MySqlConnection(myConnectionString);
MySqlCommand command = new MySqlCommand(query, connection);
For example:
<connectionStrings> <add name="MyConnectionString" connectionString="server=127.0.0.1;port=3306; database=gis_server;uid=root;pwd=1234;" /> </connectionStrings>
connection.Open();
MySqlCommand command = new MySqlCommand(query, connection); MySqlDataReader reader = command.ExecuteReader();
Your code should now be able to successfully connect to the MySQL database and execute queries and process results. For more information, see the MySQL Connector documentation on the MySQL website (https://dev.mysql.com/doc/refman/5.0/es/connector-net-examples-mysqlconnection.html).
The above is the detailed content of How to Connect to MySQL Database from ASP.NET Using the Correct Connector?. For more information, please follow other related articles on the PHP Chinese website!