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

Merge ContextConnection handling #2862

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -587,22 +587,6 @@
</example>
<exception cref="T:System.ArgumentNullException"><paramref name="keyword" /> is null (<see langword="Nothing" /> in Visual Basic)</exception>
</ContainsKey>
<ContextConnection>
<summary>
Obsolete. Gets or sets a value that indicates whether a client/server or in-process connection to SQL Server should be made.
</summary>
<value>
The value of the <see cref="P:Microsoft.Data.SqlClient.SqlConnectionStringBuilder.ContextConnection" /> property, or <see langword="false" /> if none has been supplied.
</value>
<remarks>
<para>
This property corresponds to the "Context Connection" key within the connection string.
</para>
<note type="note">
The <see cref="P:Microsoft.Data.SqlClient.SqlConnection.DataSource" /> property returns <see langword="null" /> if the connection string for the <see cref="T:Microsoft.Data.SqlClient.SqlConnection" /> is "context connection=true".
</note>
</remarks>
</ContextConnection>
<CurrentLanguage>
<summary>
Gets or sets the language used for database server warning or error messages..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,11 +1030,6 @@ public SqlConnectionStringBuilder(string connectionString) { }
[System.ComponentModel.DisplayNameAttribute("Connect Timeout")]
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
public int ConnectTimeout { get { throw null; } set { } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml' path='docs/members[@name="SqlConnectionStringBuilder"]/ContextConnection/*'/>
[System.ComponentModel.DisplayNameAttribute("Context Connection")]
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
[System.ObsoleteAttribute("ContextConnection has been deprecated. SqlConnection will ignore the 'Context Connection' keyword.")]
public bool ContextConnection { get { throw null; } set { } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml' path='docs/members[@name="SqlConnectionStringBuilder"]/CurrentLanguage/*'/>
[System.ComponentModel.DisplayNameAttribute("Current Language")]
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -955,10 +955,10 @@ internal static class DbConnectionStringDefaults
internal const string AttachDBFilename = "";
internal const int CommandTimeout = 30;
internal const int ConnectTimeout = 15;
internal const bool ContextConnection = false;

#if NETFRAMEWORK
internal const bool ConnectionReset = true;
internal const bool ContextConnection = false;
internal static readonly bool TransparentNetworkIPResolution = !LocalAppContextSwitches.DisableTNIRByDefault;
internal const string NetworkLibrary = "";
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,11 @@ internal int ExecuteNonQuery()
{
#if NETFRAMEWORK
SqlConnection.ExecutePermission.Demand();
#else
ValidateCommandBehavior(nameof(ExecuteNonQuery), CommandBehavior.Default);
#endif
using (TryEventScope.Create("SqlCommandSet.ExecuteNonQuery | API | Object Id {0}, Commands executed in Batch RPC mode", ObjectID))
{
#if NETFRAMEWORK
if (Connection.IsContextConnection)
{
throw SQL.BatchedUpdatesNotAvailableOnContextConnection();
}
ValidateCommandBehavior(nameof(ExecuteNonQuery), CommandBehavior.Default);
#endif

BatchCommand.SetBatchRPCMode(true);
BatchCommand.Parameters.Clear();
for (int index = 0; index < _commandList.Count; index++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ internal static class DEFAULT
internal static readonly SqlConnectionIPAddressPreference IpAddressPreference = DbConnectionStringDefaults.IPAddressPreference;
internal const string ServerSPN = DbConnectionStringDefaults.ServerSPN;
internal const string FailoverPartnerSPN = DbConnectionStringDefaults.FailoverPartnerSPN;
internal const bool Context_Connection = DbConnectionStringDefaults.ContextConnection;
#if NETFRAMEWORK
internal static readonly bool TransparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
internal const bool Connection_Reset = DbConnectionStringDefaults.ConnectionReset;
internal const bool Context_Connection = DbConnectionStringDefaults.ContextConnection;
internal const string Network_Library = DbConnectionStringDefaults.NetworkLibrary;
#endif // NETFRAMEWORK
}
Expand Down Expand Up @@ -261,6 +261,7 @@ internal static class TRANSACTIONBINDING
private readonly ApplicationIntent _applicationIntent;
private readonly string _applicationName;
private readonly string _attachDBFileName;
private readonly bool _contextConnection;
private readonly string _currentLanguage;
private readonly string _dataSource;
private readonly string _localDBInstance; // created based on datasource, set to NULL if datasource is not LocalDB
Expand Down Expand Up @@ -289,11 +290,8 @@ internal static class TRANSACTIONBINDING
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
internal SqlConnectionString(string connectionString) : base(connectionString, GetParseSynonyms())
{
#if NETFRAMEWORK
bool runningInProc = InOutOfProcHelper.InProc;
#else
#if !NETFRAMEWORK
ThrowUnsupportedIfKeywordSet(KEY.Connection_Reset);
ThrowUnsupportedIfKeywordSet(KEY.Context_Connection);

// Network Library has its own special error message
if (ContainsKey(KEY.Network_Library))
Expand Down Expand Up @@ -325,6 +323,7 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
_applicationIntent = ConvertValueToApplicationIntent();
_applicationName = ConvertValueToString(KEY.Application_Name, DEFAULT.Application_Name);
_attachDBFileName = ConvertValueToString(KEY.AttachDBFilename, DEFAULT.AttachDBFilename);
_contextConnection = ConvertValueToBoolean(KEY.Context_Connection, DEFAULT.Context_Connection);
_currentLanguage = ConvertValueToString(KEY.Current_Language, DEFAULT.Current_Language);
_dataSource = ConvertValueToString(KEY.Data_Source, DEFAULT.Data_Source);
_localDBInstance = LocalDBAPI.GetLocalDbInstanceNameFromServerName(_dataSource);
Expand All @@ -349,6 +348,11 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
_userID = ConvertValueToString(KEY.User_ID, DEFAULT.User_ID);
_workstationId = ConvertValueToString(KEY.Workstation_Id, null);

if (_contextConnection)
{
throw SQL.ContextConnectionIsUnsupported();
}

if (_loadBalanceTimeout < 0)
{
throw ADP.InvalidConnectionOptionValue(KEY.Load_Balance_Timeout);
Expand Down Expand Up @@ -386,35 +390,9 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
#if NETFRAMEWORK
// SQLPT 41700: Ignore ResetConnection=False (still validate the keyword/value)
_connectionReset = ConvertValueToBoolean(KEY.Connection_Reset, DEFAULT.Connection_Reset);
_contextConnection = ConvertValueToBoolean(KEY.Context_Connection, DEFAULT.Context_Connection);
_encrypt = ConvertValueToSqlConnectionEncrypt();
_enlist = ConvertValueToBoolean(KEY.Enlist, ADP.s_isWindowsNT);
_transparentNetworkIPResolution = ConvertValueToBoolean(KEY.TransparentNetworkIPResolution, DEFAULT.TransparentNetworkIPResolution);
_networkLibrary = ConvertValueToString(KEY.Network_Library, null);

if (_contextConnection)
{
// We have to be running in the engine for you to request a
// context connection.

if (!runningInProc)
{
throw SQL.ContextUnavailableOutOfProc();
}

// When using a context connection, we need to ensure that no
// other connection string keywords are specified.

foreach (KeyValuePair<string, string> entry in Parsetable)
{
if (entry.Key != KEY.Context_Connection &&
entry.Key != KEY.Type_System_Version)
{
throw SQL.ContextAllowsLimitedKeywords();
}
}
}

if (_networkLibrary != null)
{ // MDAC 83525
string networkLibrary = _networkLibrary.Trim().ToLower(CultureInfo.InvariantCulture);
Expand Down Expand Up @@ -522,12 +500,6 @@ internal SqlConnectionString(string connectionString) : base(connectionString, G
}
else if (typeSystemVersionString.Equals(TYPESYSTEMVERSION.SQL_Server_2000, StringComparison.OrdinalIgnoreCase))
{
#if NETFRAMEWORK
if (_contextConnection)
{
throw SQL.ContextAllowsOnlyTypeSystem2005();
}
#endif
_typeSystemVersion = TypeSystem.SQLServer2000;
}
else if (typeSystemVersionString.Equals(TYPESYSTEMVERSION.SQL_Server_2005, StringComparison.OrdinalIgnoreCase))
Expand Down Expand Up @@ -653,6 +625,7 @@ internal SqlConnectionString(SqlConnectionString connectionOptions, string dataS
_packetSize = connectionOptions._packetSize;
_applicationName = connectionOptions._applicationName;
_attachDBFileName = connectionOptions._attachDBFileName;
_contextConnection = connectionOptions._contextConnection;
_currentLanguage = connectionOptions._currentLanguage;
_dataSource = dataSource;
_localDBInstance = LocalDBAPI.GetLocalDbInstanceNameFromServerName(_dataSource);
Expand All @@ -676,7 +649,6 @@ internal SqlConnectionString(SqlConnectionString connectionOptions, string dataS
_hostNameInCertificate = connectionOptions._hostNameInCertificate;
#if NETFRAMEWORK
_connectionReset = connectionOptions._connectionReset;
_contextConnection = connectionOptions._contextConnection;
_transparentNetworkIPResolution = connectionOptions._transparentNetworkIPResolution;
_networkLibrary = connectionOptions._networkLibrary;
_typeSystemAssemblyVersion = connectionOptions._typeSystemAssemblyVersion;
Expand Down Expand Up @@ -721,6 +693,9 @@ internal SqlConnectionString(SqlConnectionString connectionOptions, string dataS
internal ApplicationIntent ApplicationIntent => _applicationIntent;
internal string ApplicationName => _applicationName;
internal string AttachDBFilename => _attachDBFileName;
// Return a constant value rather than _contextConnection. This allows the JIT to trim
// the code paths referencing it.
internal bool ContextConnection => false;
internal string CurrentLanguage => _currentLanguage;
internal string DataSource => _dataSource;
internal string LocalDBInstance => _localDBInstance;
Expand Down Expand Up @@ -1192,11 +1167,9 @@ internal SqlConnectionEncryptOption ConvertValueToEncrypt()
}

private readonly bool _connectionReset;
private readonly bool _contextConnection;
private readonly bool _transparentNetworkIPResolution;
private readonly string _networkLibrary;

internal bool ContextConnection => _contextConnection;
internal bool TransparentNetworkIPResolution => _transparentNetworkIPResolution;
internal string NetworkLibrary => _networkLibrary;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ private enum Keywords
IPAddressPreference,
ServerSPN,
FailoverPartnerSPN,
ContextConnection,
#if NETFRAMEWORK
ConnectionReset,
NetworkLibrary,
ContextConnection,
TransparentNetworkIPResolution,
#endif
// keep the KeywordsCount value last
Expand Down Expand Up @@ -129,7 +129,6 @@ private enum Keywords

#if NETFRAMEWORK
private bool _connectionReset = DbConnectionStringDefaults.ConnectionReset;
private bool _contextConnection = DbConnectionStringDefaults.ContextConnection;
private bool _transparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
private string _networkLibrary = DbConnectionStringDefaults.NetworkLibrary;
#else
Expand Down Expand Up @@ -181,10 +180,10 @@ private static string[] CreateValidKeywords()
validKeywords[(int)Keywords.IPAddressPreference] = DbConnectionStringKeywords.IPAddressPreference;
validKeywords[(int)Keywords.ServerSPN] = DbConnectionStringKeywords.ServerSPN;
validKeywords[(int)Keywords.FailoverPartnerSPN] = DbConnectionStringKeywords.FailoverPartnerSPN;
validKeywords[(int)Keywords.ContextConnection] = DbConnectionStringKeywords.ContextConnection;
#if NETFRAMEWORK
validKeywords[(int)Keywords.ConnectionReset] = DbConnectionStringKeywords.ConnectionReset;
validKeywords[(int)Keywords.NetworkLibrary] = DbConnectionStringKeywords.NetworkLibrary;
validKeywords[(int)Keywords.ContextConnection] = DbConnectionStringKeywords.ContextConnection;
validKeywords[(int)Keywords.TransparentNetworkIPResolution] = DbConnectionStringKeywords.TransparentNetworkIPResolution;
#endif
return validKeywords;
Expand Down Expand Up @@ -234,10 +233,9 @@ private static Dictionary<string, Keywords> CreateKeywordsDictionary()
{ DbConnectionStringKeywords.IPAddressPreference, Keywords.IPAddressPreference },
{ DbConnectionStringKeywords.ServerSPN, Keywords.ServerSPN },
{ DbConnectionStringKeywords.FailoverPartnerSPN, Keywords.FailoverPartnerSPN },

{ DbConnectionStringKeywords.ContextConnection, Keywords.ContextConnection },
#if NETFRAMEWORK
{ DbConnectionStringKeywords.ConnectionReset, Keywords.ConnectionReset },
{ DbConnectionStringKeywords.ContextConnection, Keywords.ContextConnection },
{ DbConnectionStringKeywords.TransparentNetworkIPResolution, Keywords.TransparentNetworkIPResolution },
{ DbConnectionStringKeywords.NetworkLibrary, Keywords.NetworkLibrary },
{ DbConnectionStringSynonyms.NET, Keywords.NetworkLibrary },
Expand Down Expand Up @@ -391,12 +389,12 @@ private object GetAt(Keywords index)
return ServerSPN;
case Keywords.FailoverPartnerSPN:
return FailoverPartnerSPN;
case Keywords.ContextConnection:
return false;
#if NETFRAMEWORK
#pragma warning disable 618 // Obsolete properties
case Keywords.ConnectionReset:
return ConnectionReset;
case Keywords.ContextConnection:
return ContextConnection;
#pragma warning restore 618
case Keywords.TransparentNetworkIPResolution:
return TransparentNetworkIPResolution;
Expand Down Expand Up @@ -544,13 +542,12 @@ private void Reset(Keywords index)
case Keywords.FailoverPartnerSPN:
_failoverPartnerSPN = DbConnectionStringDefaults.FailoverPartnerSPN;
break;
case Keywords.ContextConnection:
break;
#if NETFRAMEWORK
case Keywords.ConnectionReset:
_connectionReset = DbConnectionStringDefaults.ConnectionReset;
break;
case Keywords.ContextConnection:
_contextConnection = DbConnectionStringDefaults.ContextConnection;
break;
case Keywords.TransparentNetworkIPResolution:
_transparentNetworkIPResolution = DbConnectionStringDefaults.TransparentNetworkIPResolution;
break;
Expand Down Expand Up @@ -893,7 +890,6 @@ public override StandardValuesCollection GetStandardValues(ITypeDescriptorContex
#else
private static readonly string[] s_notSupportedKeywords = {
DbConnectionStringKeywords.ConnectionReset,
DbConnectionStringKeywords.ContextConnection,
DbConnectionStringKeywords.TransactionBinding,
DbConnectionStringKeywords.TransparentNetworkIPResolution,
DbConnectionStringSynonyms.TRANSPARENTNETWORKIPRESOLUTION,
Expand Down Expand Up @@ -1056,14 +1052,17 @@ public override object this[string keyword]
case Keywords.FailoverPartnerSPN:
FailoverPartnerSPN = ConvertToString(value);
break;
case Keywords.ContextConnection:
if (ConvertToBoolean(value))
{
throw SQL.ContextConnectionIsUnsupported();
}
break;
#if NETFRAMEWORK
#pragma warning disable 618 // Obsolete properties
case Keywords.ConnectionReset:
ConnectionReset = ConvertToBoolean(value);
break;
case Keywords.ContextConnection:
ContextConnection = ConvertToBoolean(value);
break;
#pragma warning restore 618
case Keywords.NetworkLibrary:
NetworkLibrary = ConvertToString(value);
Expand Down Expand Up @@ -1849,22 +1848,6 @@ public bool ConnectionReset
}
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml' path='docs/members[@name="SqlConnectionStringBuilder"]/ContextConnection/*' />
[DisplayName(DbConnectionStringKeywords.ContextConnection)]
[Obsolete("ContextConnection has been deprecated. SqlConnection will ignore the 'Context Connection' keyword.")]
[ResCategory(StringsHelper.ResourceNames.DataCategory_Source)]
[ResDescription(StringsHelper.ResourceNames.DbConnectionString_ContextConnection)]
[RefreshProperties(RefreshProperties.All)]
public bool ContextConnection
{
get => _contextConnection;
set
{
SetValue(DbConnectionStringKeywords.ContextConnection, value);
_contextConnection = value;
}
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml' path='docs/members[@name="SqlConnectionStringBuilder"]/TransparentNetworkIPResolution/*' />
[DisplayName(DbConnectionStringKeywords.TransparentNetworkIPResolution)]
[ResCategory(StringsHelper.ResourceNames.DataCategory_Source)]
Expand Down
Loading
Loading