Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -1326,11 +1326,6 @@ private void CreateOrValidateConnection(string method)
throw ADP.ConnectionRequired(method);
}

if (_connection.IsContextConnection)
{
throw SQL.NotAvailableOnContextConnection();
}

if (_ownConnection && _connection.State != ConnectionState.Open)
{
_connection.Open();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ public SqlConnection(string connectionString, SqlCredential credential) : this()
{
throw ADP.InvalidMixedArgumentOfSecureCredentialAndIntegratedSecurity();
}
else if (UsesContextConnection(connectionOptions))
{
throw ADP.InvalidMixedArgumentOfSecureCredentialAndContextConnection();
}
else if (UsesActiveDirectoryIntegrated(connectionOptions))
{
throw SQL.SettingCredentialWithIntegratedArgument();
Expand Down Expand Up @@ -459,49 +455,39 @@ public bool StatisticsEnabled
}
set
{
if (IsContextConnection)
if (value)
{
if (value)
// start
if (ConnectionState.Open == State)
{
throw SQL.NotAvailableOnContextConnection();
if (_statistics == null)
{
_statistics = new SqlStatistics();
_statistics._openTimestamp = ADP.TimerCurrent();
}
// set statistics on the parser
// update timestamp;
Debug.Assert(Parser != null, "Where's the parser?");
Parser.Statistics = _statistics;
}
}
else
{
if (value)
// stop
if (_statistics != null)
{
// start
if (ConnectionState.Open == State)
{
if (_statistics == null)
{
_statistics = new SqlStatistics();
_statistics._openTimestamp = ADP.TimerCurrent();
}
// set statistics on the parser
// remove statistics from parser
// update timestamp;
Debug.Assert(Parser != null, "Where's the parser?");
Parser.Statistics = _statistics;
TdsParser parser = Parser;
Debug.Assert(parser != null, "Where's the parser?");
parser.Statistics = null;
_statistics._closeTimestamp = ADP.TimerCurrent();
}
}
else
{
// stop
if (_statistics != null)
{
if (ConnectionState.Open == State)
{
// remove statistics from parser
// update timestamp;
TdsParser parser = Parser;
Debug.Assert(parser != null, "Where's the parser?");
parser.Statistics = null;
_statistics._closeTimestamp = ADP.TimerCurrent();
}
}
}
_collectstats = value;
}
_collectstats = value;
}
}

Expand All @@ -512,21 +498,6 @@ internal bool AsyncCommandInProgress
set => _AsyncCommandInProgress = value;
}

internal bool IsContextConnection
{
get
{
SqlConnectionString opt = (SqlConnectionString)ConnectionOptions;
return UsesContextConnection(opt);
}
}

// Is this connection is a Context Connection?
private bool UsesContextConnection(SqlConnectionString opt)
{
return opt != null && opt.ContextConnection;
}

private bool UsesActiveDirectoryIntegrated(SqlConnectionString opt)
{
return opt != null && opt.Authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated;
Expand Down Expand Up @@ -868,15 +839,8 @@ public int PacketSize
// can just return what the connection string had.
get
{
if (IsContextConnection)
{
throw SQL.NotAvailableOnContextConnection();
}

SqlInternalConnectionTds innerConnection = (InnerConnection as SqlInternalConnectionTds);
int result;

if (innerConnection != null)
if (InnerConnection is SqlInternalConnectionTds innerConnection)
{
result = innerConnection.PacketSize;
}
Expand All @@ -885,6 +849,7 @@ public int PacketSize
SqlConnectionString constr = (SqlConnectionString)ConnectionOptions;
result = constr != null ? constr.PacketSize : SqlConnectionString.DEFAULT.Packet_Size;
}

return result;
}
}
Expand Down Expand Up @@ -970,11 +935,6 @@ public string WorkstationId
{
get
{
if (IsContextConnection)
{
throw SQL.NotAvailableOnContextConnection();
}

// If not supplied by the user, the default value is the MachineName
// Note: In Longhorn you'll be able to rename a machine without
// rebooting. Therefore, don't cache this machine name.
Expand Down Expand Up @@ -1086,11 +1046,6 @@ private void CheckAndThrowOnInvalidCombinationOfConnectionStringAndSqlCredential
{
throw ADP.InvalidMixedUsageOfSecureCredentialAndIntegratedSecurity();
}

if (UsesContextConnection(connectionOptions))
{
throw ADP.InvalidMixedArgumentOfSecureCredentialAndContextConnection();
}
}

// CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessToken: check if the usage of AccessToken has any conflict
Expand All @@ -1109,11 +1064,6 @@ private void CheckAndThrowOnInvalidCombinationOfConnectionOptionAndAccessToken(S
throw ADP.InvalidMixedUsageOfAccessTokenAndIntegratedSecurity();
}

if (UsesContextConnection(connectionOptions))
{
throw ADP.InvalidMixedUsageOfAccessTokenAndContextConnection();
}

if (UsesAuthentication(connectionOptions))
{
throw ADP.InvalidMixedUsageOfAccessTokenAndAuthentication();
Expand Down Expand Up @@ -1328,10 +1278,6 @@ public static void ClearPool(SqlConnection connection)
if (connectionOptions != null)
{
connectionOptions.DemandPermission();
if (connection.IsContextConnection)
{
throw SQL.NotAvailableOnContextConnection();
}
SqlConnectionFactory.SingletonInstance.ClearPool(connection);
}
}
Expand Down Expand Up @@ -1446,21 +1392,12 @@ private void DisposeMe(bool disposing)
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/EnlistDistributedTransaction/*' />
public void EnlistDistributedTransaction(System.EnterpriseServices.ITransaction transaction)
{
if (IsContextConnection)
{
throw SQL.NotAvailableOnContextConnection();
}

public void EnlistDistributedTransaction(System.EnterpriseServices.ITransaction transaction) =>
EnlistDistributedTransactionHelper(transaction);
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/Open/*' />
public override void Open()
{
public override void Open() =>
Open(SqlConnectionOverrides.None);
}

private bool TryOpenWithRetry(TaskCompletionSource<DbConnectionInternal> retry, SqlConnectionOverrides overrides)
=> RetryLogicProvider.Execute(this, () => TryOpen(retry, overrides));
Expand Down Expand Up @@ -1773,13 +1710,6 @@ private Task InternalOpenAsync(SqlConnectionOverrides overrides, CancellationTok
return result.Task;
}

if (IsContextConnection)
{
// Async not supported on Context Connections
result.SetException(ADP.ExceptionWithStackTrace(SQL.NotAvailableOnContextConnection()));
return result.Task;
}

bool completed;

try
Expand Down Expand Up @@ -2275,12 +2205,8 @@ public static void ChangePassword(string connectionString, string newPassword)
{
throw SQL.ChangePasswordUseOfUnallowedKey(SqlConnectionString.KEY.AttachDBFilename);
}
if (connectionOptions.ContextConnection)
{
throw SQL.ChangePasswordUseOfUnallowedKey(SqlConnectionString.KEY.Context_Connection);
}

System.Security.PermissionSet permissionSet = connectionOptions.CreatePermissionSet();
PermissionSet permissionSet = connectionOptions.CreatePermissionSet();
permissionSet.Demand();

ChangePassword(connectionString, connectionOptions, null, newPassword, null);
Expand Down Expand Up @@ -2340,12 +2266,7 @@ public static void ChangePassword(string connectionString, SqlCredential credent
throw SQL.ChangePasswordUseOfUnallowedKey(SqlConnectionString.KEY.AttachDBFilename);
}

if (connectionOptions.ContextConnection)
{
throw SQL.ChangePasswordUseOfUnallowedKey(SqlConnectionString.KEY.Context_Connection);
}

System.Security.PermissionSet permissionSet = connectionOptions.CreatePermissionSet();
PermissionSet permissionSet = connectionOptions.CreatePermissionSet();
permissionSet.Demand();

ChangePassword(connectionString, connectionOptions, credential, null, newSecurePassword);
Expand Down Expand Up @@ -2419,11 +2340,6 @@ internal Task<T> RegisterForConnectionCloseNotification<T>(Task<T> outerTask, ob
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/ResetStatistics/*' />
public void ResetStatistics()
{
if (IsContextConnection)
{
throw SQL.NotAvailableOnContextConnection();
}

if (Statistics != null)
{
Statistics.Reset();
Expand All @@ -2438,11 +2354,6 @@ public void ResetStatistics()
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/RetrieveStatistics/*' />
public IDictionary RetrieveStatistics()
{
if (IsContextConnection)
{
throw SQL.NotAvailableOnContextConnection();
}

if (Statistics != null)
{
UpdateStatistics();
Expand Down
Loading
Loading