I want to set the program name in the connection string. Seems like the way it should be set up is through the conn_attrs
attribute in the MySql connection string. Here’s the code:
var builder = new MySqlConnectionStringBuilder()
{
Server = "myip",
UserID = "myuser",
Password = "mypass",
Database = "mydb",
SslMode = MySqlSslMode.Required,
ConnectionTimeout = 30,
CharacterSet = "utf8mb4",
};
var cs = $"{builder.ConnectionString};conn_attrs=program_name:alireza";
using var conn = new MySqlConnection(cs);
using var cmd = new MySqlCommand("Select BookId From Books", conn);
conn.Open();
using var reader = await cmd.ExecuteReaderAsync();
while(await reader.ReadAsync())
{
int id = reader.GetInt32(0);
}
However, it seems like this is not supported. I’m getting the following error:
Option not supported.
Parameter name: conn_attrs
I’m using these NuGet packages:
MySql.Data Version=8.0.32
MySql.Data.EntityFramework Version=8.0.32
Any solutions?
2
Answers
According to the documentation the option for setting connection attributes is
connection-attributes
.Please make sure that PERFORMANCE_SCHEMA is enabled on your database server, otherwise this option has no effect.
This is not possible with the MySql.Data package. The alternative NuGet package, MySqlConnector (disclaimer: lead author), does support this via the
Application Name
connection string option: https://mysqlconnector.net/connection-options/#ApplicationName.Unfortuately, there is no replacement for MySql.Data.EntityFramework that works with MySqlConnector. The only option is Pomelo.EntityFrameworkCore.MySql, which is EF Core, not Entity Framework.