Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: Add invariant culture check result caching #376

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ namespace Microsoft.Data.SqlClient
/// <include file='..\..\..\..\..\..\..\doc\snippets\Microsoft.Data.SqlClient\SqlConnection.xml' path='docs/members[@name="SqlConnection"]/SqlConnection/*' />
public sealed partial class SqlConnection : DbConnection, ICloneable
{
private enum CultureCheckState : uint
{
Unknown = 0,
Standard = 1,
Invariant = 2
}

private bool _AsyncCommandInProgress;

Expand Down Expand Up @@ -72,7 +78,9 @@ private static readonly Dictionary<string, SqlColumnEncryptionKeyStoreProvider>
};

// Lock to control setting of _CustomColumnEncryptionKeyStoreProviders
private static readonly Object _CustomColumnEncryptionKeyProvidersLock = new Object();
private static readonly object _CustomColumnEncryptionKeyProvidersLock = new object();
// status of invariant culture environment check
private static CultureCheckState _cultureCheckState;

/// <summary>
/// Custom provider list should be provided by the user. We shallow copy the user supplied dictionary into a ReadOnlyDictionary.
Expand Down Expand Up @@ -1408,13 +1416,20 @@ private bool TryOpen(TaskCompletionSource<DbConnectionInternal> retry)
{
SqlConnectionString connectionOptions = (SqlConnectionString)ConnectionOptions;

// .NET Core 2.0 and up supports a Globalization Invariant Mode to reduce the size of
// required libraries for applications which don't need globalization support. SqlClient
// requires those libraries for core functionality and will throw exceptions later if they
// are not present. Throwing on open with a meaningful message helps identify the issue.
if (CultureInfo.GetCultureInfo("en-US").EnglishName.Contains("Invariant"))
if (_cultureCheckState != CultureCheckState.Standard)
{
throw SQL.GlobalizationInvariantModeNotSupported();
// .NET Core 2.0 and up supports a Globalization Invariant Mode to reduce the size of
// required libraries for applications which don't need globalization support. SqlClient
// requires those libraries for core functionality and will throw exceptions later if they
// are not present. Throwing on open with a meaningful message helps identify the issue.
if (_cultureCheckState == CultureCheckState.Unknown)
{
_cultureCheckState = CultureInfo.GetCultureInfo("en-US").EnglishName.Contains("Invariant") ? CultureCheckState.Invariant : CultureCheckState.Standard;
}
if (_cultureCheckState == CultureCheckState.Invariant)
{
throw SQL.GlobalizationInvariantModeNotSupported();
}
}

_applyTransientFaultHandling = (retry == null && connectionOptions != null && connectionOptions.ConnectRetryCount > 0);
Expand Down