2021年4月8日 星期四

ASP.NET C# MariaDB 連結字串

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();

沒有留言:

ASP.NET C# MariaDB 連結字串

web.config  加入下面內容 <connectionStrings> <add name=" connect string " connectionString="server= IP ;user id= user name...