MySqlConnector icon indicating copy to clipboard operation
MySqlConnector copied to clipboard

Add support .ChangeUser() for MySqlConnection

Open yukozh opened this issue 8 years ago • 4 comments
trafficstars

yukozh avatar Aug 28 '17 08:08 yukozh

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?)

bgrainger avatar Aug 28 '17 15:08 bgrainger

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

yukozh avatar Aug 29 '17 01:08 yukozh

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.

bgrainger avatar Aug 29 '17 02:08 bgrainger

See also https://github.com/dotnet/corefx/issues/23597. Moved to https://github.com/dotnet/runtime/issues/23349.

bgrainger avatar Mar 14 '19 03:03 bgrainger

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).

bgrainger avatar Dec 23 '22 18:12 bgrainger