在mysql连接字符串中添加应用程序名称/程序名称 [英] Add Application Name / Program Name in mysql connection string
问题描述
我正在寻找在连接字符串中添加应用程序名称或程序名称的解决方案,以使其在"MySQL Workbench"的客户端连接"下可见.
I am searching for a solution to add application name or program name in connection string so that it is visible under "Client Connection" in "MySQL Workbench".
SQL Server:MySql Server 5.6 | .Net DLL版本:8.0.11.0(从 https://dev.mysql下载.com/downloads/connector/net/8.0.html )
SQL Server : MySql Server 5.6 | .Net DLL Version : 8.0.11.0 (download from https://dev.mysql.com/downloads/connector/net/8.0.html)
这是我的连接字符串
private static string myConnectionString = string.Format("server=192.168.2.2;uid={0};pwd={1};database=databse;SslMode
= none;Application Name=My Application;", Username, Password);
推荐答案
MySQL Workbench中的程序名称"列来自 MySQL文档错误声称:
The "Program Name" column in MySQL Workbench comes from a program_name
connection attribute. The MySQL documentation incorrectly claims that:
MySQL Connector/NET定义了以下属性:
MySQL Connector/NET defines these attributes:
-
_program_name
:客户端名称
_program_name
: The client name
这有两种错误:属性名称有一个错字(下划线)和对其进行设置的代码
This is wrong in two ways: the attribute name has a typo (leading underscore) and the code that sets it was deleted.
无法(在连接字符串设置中或其他方式)在MySQL Connector/NET中设置此属性的值.此外,连接属性为 part ,因此无法在建立连接后(例如,在您的应用程序代码中)设置它们.
There is no way (a connection string setting or otherwise) to set the value of this attribute in MySQL Connector/NET. Furthermore, the connection attributes are part of the initial handshake so there is no way to set them after the connection is established (e.g., in your application code).
如果您愿意更改ADO.NET连接器库,请 MySqlConnector 库 v0.44.0 ;这将使您可以控制发送到服务器的连接属性(它将显示在MySQL Workbench中).
If you're willing to change ADO.NET connector libraries, the MySqlConnector library added support for an Application Name
connection string option in v0.44.0; this will let you control the connection attribute that's sent to the server (and it will show up in MySQL Workbench).
这篇关于在mysql连接字符串中添加应用程序名称/程序名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!