web.config 加入下面內容
<connectionStrings>
<add name="connect string" connectionString="server=IP;user id=user name;password=Password;Persist Security Info=True;Database=DB name;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
程式引用
using MySql.Data.MySqlClient;
........
MySqlConnectionStringBuilder sqlsb = new MySqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["connect string"].ConnectionString);
MySqlConnection MySqlConnection = new MySqlConnection(sqlsb.ConnectionString);
string sqlStatement = @"select * from test";
MySqlCommand MySqlCommand = new MySqlCommand(sqlStatement);
MySqlCommand.Connection = MySqlConnection;
MySqlConnection.Open();