/// <summary> /// Create a SNI connection handle /// </summary> /// <param name="callbackObject">Asynchronous I/O callback object</param> /// <param name="fullServerName">Full server name from connection string</param> /// <param name="ignoreSniOpenTimeout">Ignore open timeout</param> /// <param name="timerExpire">Timer expiration</param> /// <param name="instanceName">Instance name</param> /// <param name="spnBuffer">SPN</param> /// <param name="flushCache">Flush packet cache</param> /// <param name="async">Asynchronous connection</param> /// <param name="parallel">Attempt parallel connects</param> /// <returns>SNI handle</returns> public SNIHandle CreateConnectionHandle(object callbackObject, string fullServerName, bool ignoreSniOpenTimeout, long timerExpire, out byte[] instanceName, ref byte[] spnBuffer, bool flushCache, bool async, bool parallel, bool isIntegratedSecurity) { instanceName = new byte[1]; DataSource details = DataSource.ParseServerName(fullServerName); if (details == null) { return(null); } SNIHandle sniHandle = null; switch (details.ConnectionProtocol) { case DataSource.Protocol.TCP: sniHandle = CreateTcpHandle(details, timerExpire, callbackObject, parallel, ref spnBuffer, isIntegratedSecurity); break; case DataSource.Protocol.NP: sniHandle = CreateNpHandle(details, timerExpire, callbackObject, parallel); break; case DataSource.Protocol.None: // default to using tcp if no protocol is provided sniHandle = CreateTcpHandle(details, timerExpire, callbackObject, parallel, ref spnBuffer, isIntegratedSecurity); break; default: Debug.Fail($"Unexpected connection protocol: {details.ConnectionProtocol}"); break; } return(sniHandle); }
/// <summary> /// Create a SNI connection handle /// </summary> /// <param name="callbackObject">Asynchronous I/O callback object</param> /// <param name="fullServerName">Full server name from connection string</param> /// <param name="ignoreSniOpenTimeout">Ignore open timeout</param> /// <param name="timerExpire">Timer expiration</param> /// <param name="instanceName">Instance name</param> /// <param name="spnBuffer">SPN</param> /// <param name="flushCache">Flush packet cache</param> /// <param name="async">Asynchronous connection</param> /// <param name="parallel">Attempt parallel connects</param> /// <returns>SNI handle</returns> public SNIHandle CreateConnectionHandle(object callbackObject, string fullServerName, bool ignoreSniOpenTimeout, long timerExpire, out byte[] instanceName, ref byte[] spnBuffer, bool flushCache, bool async, bool parallel, bool isIntegratedSecurity) { instanceName = new byte[1]; bool errorWithLocalDBProcessing; string localDBDataSource = GetLocalDBDataSource(fullServerName, out errorWithLocalDBProcessing); if (errorWithLocalDBProcessing) { return(null); } // If a localDB Data source is available, we need to use it. fullServerName = localDBDataSource ?? fullServerName; DataSource details = DataSource.ParseServerName(fullServerName); if (details == null) { return(null); } SNIHandle sniHandle = null; switch (details.ConnectionProtocol) { case DataSource.Protocol.TCP: sniHandle = CreateTcpHandle(details, timerExpire, callbackObject, parallel); break; case DataSource.Protocol.NP: sniHandle = CreateNpHandle(details, timerExpire, callbackObject, parallel); break; case DataSource.Protocol.None: // default to using tcp if no protocol is provided sniHandle = CreateTcpHandle(details, timerExpire, callbackObject, parallel); break; default: Debug.Fail($"Unexpected connection protocol: {details.ConnectionProtocol}"); break; } if (isIntegratedSecurity) { try { spnBuffer = GetSqlServerSPN(details); } catch (Exception e) { SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); } } return(sniHandle); }
/// <summary> /// Create a SNI connection handle /// </summary> /// <param name="callbackObject">Asynchronous I/O callback object</param> /// <param name="fullServerName">Full server name from connection string</param> /// <param name="ignoreSniOpenTimeout">Ignore open timeout</param> /// <param name="timerExpire">Timer expiration</param> /// <param name="instanceName">Instance name</param> /// <param name="spnBuffer">SPN</param> /// <param name="flushCache">Flush packet cache</param> /// <param name="async">Asynchronous connection</param> /// <param name="parallel">Attempt parallel connects</param> /// <returns>SNI handle</returns> public SNIHandle CreateConnectionHandle(object callbackObject, string fullServerName, bool ignoreSniOpenTimeout, long timerExpire, out byte[] instanceName, ref byte[] spnBuffer, bool flushCache, bool async, bool parallel, bool isIntegratedSecurity) { instanceName = new byte[1]; DataSource details = DataSource.ParseServerName(fullServerName); if (details == null) { return(null); } if (isIntegratedSecurity) { string hostName = details.ServerName; int connPort = details.Port; string connInstanceName = details.InstanceName; try { spnBuffer = GetSqlServerSPN(hostName, (connPort >= 0 ? connPort.ToString() : connInstanceName)); } catch (Exception e) { SNILoadHandle.SingletonInstance.LastError = new SNIError(SNIProviders.INVALID_PROV, SNICommon.ErrorSpnLookup, e); return(null); } } SNIHandle sniHandle = null; switch (details.ConnectionProtocol) { case DataSource.Protocol.TCP: sniHandle = CreateTcpHandle(details, timerExpire, callbackObject, parallel); break; case DataSource.Protocol.NP: sniHandle = CreateNpHandle(details, timerExpire, callbackObject, parallel); break; case DataSource.Protocol.None: // default to using tcp if no protocol is provided sniHandle = CreateTcpHandle(details, timerExpire, callbackObject, parallel); break; default: Debug.Fail($"Unexpected connection protocol: {details.ConnectionProtocol}"); break; } return(sniHandle); }