private void InitializeCredentialsHandle(ConnectionInfo connectionInfo)
        {
            string sspi = connectionInfo.Sspi;

            if (connectionInfo.ImpersonationLevel == ImpersonationLevel.Anonymous)
            {
                if (this.m_isSchannel)
                {
                    if (string.IsNullOrEmpty(connectionInfo.Certificate))
                    {
                        this.m_CredentialsHandle = new CredentialsContext(null);
                        return;
                    }
                    throw new AdomdConnectionException(XmlaSR.Authentication_Sspi_SchannelAnonymousAmbiguity, null, ConnectionExceptionCause.AuthenticationFailed);
                }
                else
                {
                    IntPtr currentThread = UnsafeNclNativeMethods.GetCurrentThread();
                    if (!UnsafeNclNativeMethods.ImpersonateAnonymousToken(currentThread))
                    {
                        uint lastError = UnsafeNclNativeMethods.GetLastError();
                        throw new Win32Exception((int)lastError);
                    }
                    try
                    {
                        this.m_CredentialsHandle = new CredentialsContext(sspi, CredentialUse.Outgoing);
                        return;
                    }
                    finally
                    {
                        if (!UnsafeNclNativeMethods.RevertToSelf())
                        {
                            Process.GetCurrentProcess().Kill();
                        }
                    }
                }
            }
            if (this.m_isSchannel)
            {
                string certificate = connectionInfo.Certificate;
                if (string.IsNullOrEmpty(certificate))
                {
                    this.m_CredentialsHandle = new CredentialsContext(null);
                    return;
                }
                this.m_CredentialsHandle = new CredentialsContext(CertUtils.LoadCertificateByThumbprint(certificate, true));
                return;
            }
            else
            {
                this.m_CredentialsHandle = new CredentialsContext(sspi, CredentialUse.Outgoing);
            }
        }
 private void ReleaseResources()
 {
     if (this.lpCookie != this.InvalidHandleValue)
     {
         UnsafeNclNativeMethods.DeactivateActCtx(0, this.lpCookie);
     }
     this.lpCookie = this.InvalidHandleValue;
     if (this.hCtx == this.InvalidHandleValue)
     {
         UnsafeNclNativeMethods.ReleaseActCtx(this.hCtx);
     }
     this.hCtx = this.InvalidHandleValue;
 }