RaUI/Source/packages/MySqlConnector.2.3.1/README.md
zilinsoft b4e236fd55 ### 2025-01-06 星期一更新
------
#### OnLineUpgradeConfig    V1.0.2501.0601
- *.[修复]修复用户管理列表无法默认勾选已选择用户的BUG。
#### RaUI    V4.0.2501.0601
- *.[新增]RyFiles类新增SetFileDate、SetFileCreationTime、SetFileLastWriteTime方法。
- *.[新增]RyFiles.CopyBigFile方法现在会同步来源文件的创建和修改时间。
- *.[新增]ryQuickSQL类新增GetPostData函数,将数据快速转成Post数据。
- *.[改进]执行MySQL下的ExecuteNonQuery时,如果遇到连接关闭错误,允许重连并重新执行。
- *.[改进]IDbInterface在执行新的SQL语句前,自动清空最后错误。
- *.[修复]修复LayeredForm窗体以正常窗体打开的时候,文本框无法编辑的BUG。
- *.[修复]修复ApkOp获取apk权限时可能带乱码的BUG。
- *.[修复]修复WeifenLuo.WinFormsUI.Docking的ResourceManager.GetString路径不对导致报错的BUG。
2025-01-06 11:14:35 +08:00

3.1 KiB

About

MySqlConnector is a C# ADO.NET driver for MySQL, MariaDB, Amazon Aurora, Azure Database for MySQL and other MySQL-compatible databases.

More documentation is available at the MySqlConnector website.

How to Use

// set these values correctly for your database server
var builder = new MySqlConnectionStringBuilder
{
	Server = "your-server",
	UserID = "database-user",
	Password = "P@ssw0rd!",
	Database = "database-name",
};

// open a connection asynchronously
using var connection = new MySqlConnection(builder.ConnectionString);
await connection.OpenAsync();

// create a DB command and set the SQL statement with parameters
using var command = connection.CreateCommand();
command.CommandText = @"SELECT * FROM orders WHERE order_id = @OrderId;";
command.Parameters.AddWithValue("@OrderId", orderId);

// execute the command and read the results
using var reader = await command.ExecuteReaderAsync();
while (reader.Read())
{
	var id = reader.GetInt32("order_id");
	var date = reader.GetDateTime("order_date");
	// ...
}

ASP.NET

For ASP.NET, use the MySqlConnector.DependencyInjection package to integrate with dependency injection and logging.

var builder = WebApplication.CreateBuilder(args);

// use AddMySqlDataSource to configure MySqlConnector
builder.Services.AddMySqlDataSource(builder.Configuration.GetConnectionString("Default"));

var app = builder.Build();

// use dependency injection to get a MySqlConnection in minimal APIs or in controllers
app.MapGet("/", async (MySqlConnection connection) =>
{
    // open and use the connection here
    await connection.OpenAsync();
    await using var command = connection.CreateCommand();
    command.CommandText = "SELECT name FROM users LIMIT 1";
    return "Hello World: " + await command.ExecuteScalarAsync();
});

app.Run();

Key Features

  • Full support for async I/O
  • High performance
  • Supports .NET Framework, .NET Core, and .NET 5.0+

Main Types

The main types provided by this library are:

  • MySqlConnection (implementation of DbConnection)
  • MySqlCommand (implementation of DbCommand)
  • MySqlDataReader (implementation of DbDataReader)
  • MySqlBulkCopy
  • MySqlBulkLoader
  • MySqlConnectionStringBuilder
  • MySqlConnectorFactory
  • MySqlDataAdapter
  • MySqlException
  • MySqlTransaction (implementation of DbTransaction)

Feedback

MySqlConnector is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.