MySqlConnector
MySqlConnector copied to clipboard
Add support .ChangeUser() for MySqlConnection
What is the API signature and behaviour of this proposed method?
(I don't see an equivalent method on MySqlConnection, NpgsqlConnection or SqlConnection; is there an existing example you're referencing?)
That was not a standard api for ADO.NET but supported in other platforms like PHP: http://www.php.net/manual/en/mysqli.change-user.php
Proposed API:
void ChangeUser(string userName, string password, string database = null);
Task ChangeUserAsync(string userName, string password, string database = null, CancellationToken cancellationToken = default);
Specifying a database parameter can optionally change the current database when signing in as the new user; otherwise the database is unchanged.
Unlike ChangeDatabase, there is no equivalent property to DatabaseName that can return the username of the logged-in user. A corollary is that there is no way for the consumer to determine if the user has been changed on an active connection.
Connections for which the user has been changed will not be returned to the pool when they are closed. As a result, it would be much more efficient to have two connection strings (one for each user) and simply open a new connection (which will be pooled by default) instead of changing the user on an existing connection.
See also https://github.com/dotnet/corefx/issues/23597. Moved to https://github.com/dotnet/runtime/issues/23349.
As per earlier comments, there is little value in adding this API, and it could encourage inefficient use of the connector (compared to using two separate connection pools).