private void ProcessSSPI(int receivedLength)
{
SniContext outerContext = _physicalStateObj.SniContext;
_physicalStateObj.SniContext = SniContext.Snix_ProcessSspi;
// allocate received buffer based on length from SSPI message
byte[] receivedBuff = new byte[receivedLength];
// read SSPI data received from server
Debug.Assert(_physicalStateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
bool result = _physicalStateObj.TryReadByteArray(receivedBuff, 0, receivedLength);
if (!result) { throw SQL.SynchronousCallMayNotPend(); }
// allocate send buffer and initialize length
byte[] sendBuff = new byte[s_maxSSPILength];
UInt32 sendLength = s_maxSSPILength;
// make call for SSPI data
SSPIData(receivedBuff, (UInt32)receivedLength, sendBuff, ref sendLength);
// DO NOT SEND LENGTH - TDS DOC INCORRECT! JUST SEND SSPI DATA!
_physicalStateObj.WriteByteArray(sendBuff, (int)sendLength, 0);
// set message type so server knows its a SSPI response
_physicalStateObj._outputMessageType = TdsEnums.MT_SSPI;
// send to server
_physicalStateObj.WritePacket(TdsEnums.HARDFLUSH);
_physicalStateObj.SniContext = outerContext;
}