- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
运行此代码时:
static void Main(string[] args)
{
SqlConnectionStringBuilder csb = new SqlConnectionStringBuilder();
csb.DataSource = @"8.8.8.8"; // some inaccessible ip address
csb.InitialCatalog = "Tempdb";
csb.IntegratedSecurity = true;
csb.ConnectTimeout = 1;
DateTime start = DateTime.Now;
try
{
new SqlConnection(csb.ToString()).Open();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
Console.Write(string.Format("{0} seconds", DateTime.Now.Subtract(start).TotalSeconds));
}
}
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
47.6097605 seconds
csb.FailoverPartner=@"9.9.9.9";
最佳答案
编辑 : 尽管这看起来很奇怪,但我在反编译代码的深处放置了一个断点,并使用 --> 将超时设置为 1。有效 <-- 服务器名称,我让我的断点在那里然后继续,它给出了超时过期异常 正如预期的那样因此,似乎 ConnectTimeout 仅在能够解析服务器并等待连接时才适用。它不影响解析要连接的服务器。我认为所经历的时间是用于服务器解析,而不是用于“连接”的实际行为。至少这是我目前的假设。
我用反射器来看看被子下面发生了什么。也许有人来自 微软 可以在这里帮助我们,因为我还发现 ConnectTimeout 似乎对初始连接没有影响。
无论如何在内部建立连接,我认为以下方法被调用,在这个序列中:
internal DbConnectionInternal CreatePooledConnection(DbConnection owningConnection, DbConnectionPool pool, DbConnectionOptions options)
{
DbConnectionPoolGroupProviderInfo providerInfo = pool.PoolGroup.ProviderInfo;
DbConnectionInternal internal2 = this.CreateConnection(options, providerInfo, pool, owningConnection);
if (internal2 != null)
{
this.PerformanceCounters.HardConnectsPerSecond.Increment();
internal2.MakePooledConnection(pool);
}
Bid.Trace("<prov.DbConnectionFactory.CreatePooledConnection|RES|CPOOL> %d#, Pooled database connection created.\n", this.ObjectID);
return internal2;
}
protected override DbConnectionInternal CreateConnection(DbConnectionOptions options, object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection)
{
string instanceName;
SqlConnectionString str = (SqlConnectionString) options;
if (str.ContextConnection)
{
return this.GetContextConnection(str, poolGroupProviderInfo, owningConnection);
}
bool redirectedUserInstance = false;
DbConnectionPoolIdentity current = null;
if (str.IntegratedSecurity)
{
if (pool != null)
{
current = pool.Identity;
}
else
{
current = DbConnectionPoolIdentity.GetCurrent();
}
}
if (!str.UserInstance)
{
goto Label_00F1;
}
redirectedUserInstance = true;
if ((pool == null) || ((pool != null) && (pool.Count <= 0)))
{
using (SqlInternalConnectionTds tds = null)
{
SqlConnectionString connectionOptions = new SqlConnectionString(str, str.DataSource, true, false);
tds = new SqlInternalConnectionTds(current, connectionOptions, null, "", null, false);
instanceName = tds.InstanceName;
if (!instanceName.StartsWith(@"\\.\", StringComparison.Ordinal))
{
throw SQL.NonLocalSSEInstance();
}
if (pool != null)
{
SqlConnectionPoolProviderInfo info2 = (SqlConnectionPoolProviderInfo) pool.ProviderInfo;
info2.InstanceName = instanceName;
}
goto Label_00DB;
}
}
SqlConnectionPoolProviderInfo providerInfo = (SqlConnectionPoolProviderInfo) pool.ProviderInfo;
instanceName = providerInfo.InstanceName;
Label_00DB:
str = new SqlConnectionString(str, instanceName, false, null);
poolGroupProviderInfo = null;
Label_00F1:
return new SqlInternalConnectionTds(current, str, poolGroupProviderInfo, "", (SqlConnection) owningConnection, redirectedUserInstance);
}
internal SqlInternalConnectionTds(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, object providerInfo, string newPassword, SqlConnection owningObject, bool redirectedUserInstance) : base(connectionOptions)
{
this._instanceName = string.Empty;
if (connectionOptions.UserInstance && InOutOfProcHelper.InProc)
{
throw SQL.UserInstanceNotAvailableInProc();
}
this._identity = identity;
this._poolGroupProviderInfo = (SqlConnectionPoolGroupProviderInfo) providerInfo;
this._fResetConnection = connectionOptions.ConnectionReset;
if (this._fResetConnection)
{
this._originalDatabase = connectionOptions.InitialCatalog;
this._originalLanguage = connectionOptions.CurrentLanguage;
}
RuntimeHelpers.PrepareConstrainedRegions();
try
{
TimeoutTimer timeout = TimeoutTimer.StartSecondsTimeout(connectionOptions.ConnectTimeout);
this.OpenLoginEnlist(owningObject, timeout, connectionOptions, newPassword, redirectedUserInstance);
}
catch (OutOfMemoryException)
{
base.DoomThisConnection();
throw;
}
catch (StackOverflowException)
{
base.DoomThisConnection();
throw;
}
catch (ThreadAbortException)
{
base.DoomThisConnection();
throw;
}
if (Bid.AdvancedOn)
{
Bid.Trace("<sc.SqlInternalConnectionTds.ctor|ADV> %d#, constructed new TDS internal connection\n", base.ObjectID);
}
}
private void LoginNoFailover(ServerInfo serverInfo, string newPassword, bool redirectedUserInstance, SqlConnection owningObject, SqlConnectionString connectionOptions, TimeoutTimer timeout)
{
if (Bid.AdvancedOn)
{
Bid.Trace("<sc.SqlInternalConnectionTds.LoginNoFailover|ADV> %d#, host=%ls\n", base.ObjectID, serverInfo.UserServerName);
}
int num = 100;
this.ResolveExtendedServerName(serverInfo, !redirectedUserInstance, owningObject);
while (true)
{
if (this._parser != null)
{
this._parser.Disconnect();
}
this._parser = new TdsParser(base.ConnectionOptions.MARS, base.ConnectionOptions.Asynchronous);
try
{
this.AttemptOneLogin(serverInfo, newPassword, true, timeout, owningObject);
break;
}
catch (SqlException exception)
{
if (((this._parser == null) || (this._parser.State != TdsParserState.Closed)) || (this.IsDoNotRetryConnectError(exception.Number) || timeout.IsExpired))
{
throw;
}
if (timeout.MillisecondsRemaining <= num)
{
throw;
}
}
if (this.ServerProvidedFailOverPartner != null)
{
this.LoginWithFailover(true, serverInfo, this.ServerProvidedFailOverPartner, newPassword, redirectedUserInstance, owningObject, connectionOptions, timeout);
return;
}
if (Bid.AdvancedOn)
{
Bid.Trace("<sc.SqlInternalConnectionTds.LoginNoFailover|ADV> %d#, sleeping %d{milisec}\n", base.ObjectID, num);
}
Thread.Sleep(num);
num = (num < 500) ? (num * 2) : 0x3e8;
}
if (this.PoolGroupProviderInfo != null)
{
this.PoolGroupProviderInfo.FailoverCheck(this, false, connectionOptions, this.ServerProvidedFailOverPartner);
}
base.CurrentDataSource = serverInfo.UserServerName;
}
internal void Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, bool ignoreSniOpenTimeout, long timerExpire, bool encrypt, bool trustServerCert, bool integratedSecurity)
{
if (this._state == TdsParserState.Closed)
{
this._connHandler = connHandler;
if (SNILoadHandle.SingletonInstance.SNIStatus != 0)
{
this.Errors.Add(this.ProcessSNIError(this._physicalStateObj));
this._physicalStateObj.Dispose();
this.ThrowExceptionAndWarning();
}
if (integratedSecurity)
{
this.LoadSSPILibrary();
this._sniServerUserName = new byte[s_maxSSPILength];
Bid.Trace("<sc.TdsParser.Connect|SEC> SSPI authentication\n");
}
else
{
Bid.Trace("<sc.TdsParser.Connect|SEC> SQL authentication\n");
}
byte[] instanceName = null;
this._physicalStateObj.CreatePhysicalSNIHandle(serverInfo.ExtendedServerName, ignoreSniOpenTimeout, timerExpire, out instanceName, integratedSecurity, this._sniServerUserName, false, this._fAsync);
if (this._physicalStateObj.Status != 0)
{
this.Errors.Add(this.ProcessSNIError(this._physicalStateObj));
this._physicalStateObj.Dispose();
Bid.Trace("<sc.TdsParser.Connect|ERR|SEC> Login failure\n");
this.ThrowExceptionAndWarning();
}
this._server = serverInfo.ResolvedServerName;
if (connHandler.PoolGroupProviderInfo != null)
{
connHandler.PoolGroupProviderInfo.AliasCheck(serverInfo.ResolvedServerName);
}
this._state = TdsParserState.OpenNotLoggedIn;
this._physicalStateObj.SniContext = SniContext.Snix_PreLoginBeforeSuccessfullWrite;
this._physicalStateObj.TimeoutTime = timerExpire;
bool marsCapable = false;
this.SendPreLoginHandshake(instanceName, encrypt);
this._physicalStateObj.SniContext = SniContext.Snix_PreLogin;
switch (this.ConsumePreLoginHandshake(encrypt, trustServerCert, out marsCapable))
{
case PreLoginHandshakeStatus.SphinxFailure:
this._fMARS = false;
this._physicalStateObj._sniPacket = null;
this._physicalStateObj.SniContext = SniContext.Snix_Connect;
this._physicalStateObj.CreatePhysicalSNIHandle(serverInfo.ExtendedServerName, ignoreSniOpenTimeout, timerExpire, out instanceName, integratedSecurity, this._sniServerUserName, false, this._fAsync);
if (this._physicalStateObj.Status != 0)
{
this.Errors.Add(this.ProcessSNIError(this._physicalStateObj));
Bid.Trace("<sc.TdsParser.Connect|ERR|SEC> Login failure\n");
this.ThrowExceptionAndWarning();
}
break;
case PreLoginHandshakeStatus.InstanceFailure:
this._physicalStateObj.Dispose();
this._physicalStateObj.SniContext = SniContext.Snix_Connect;
this._physicalStateObj.CreatePhysicalSNIHandle(serverInfo.ExtendedServerName, ignoreSniOpenTimeout, timerExpire, out instanceName, integratedSecurity, this._sniServerUserName, true, this._fAsync);
if (this._physicalStateObj.Status != 0)
{
this.Errors.Add(this.ProcessSNIError(this._physicalStateObj));
Bid.Trace("<sc.TdsParser.Connect|ERR|SEC> Login failure\n");
this.ThrowExceptionAndWarning();
}
this.SendPreLoginHandshake(instanceName, encrypt);
if (this.ConsumePreLoginHandshake(encrypt, trustServerCert, out marsCapable) == PreLoginHandshakeStatus.InstanceFailure)
{
Bid.Trace("<sc.TdsParser.Connect|ERR|SEC> Login failure\n");
throw SQL.InstanceFailure();
}
break;
}
if (this._fMARS && marsCapable)
{
this._sessionPool = new TdsParserSessionPool(this);
}
else
{
this._fMARS = false;
}
}
}
关于sql-server - 为什么在这种情况下忽略 ConnectTimeout?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8170084/
在我的应用程序中,我打开 UrlConnections,并设置连接超时。有时,会抛出超时,但输入流仍然可读(并且包含数据) 我使用以下代码成功地重现了这一点: System.setProper
运行此代码时: static void Main(string[] args) { SqlConnectionStringBuilder csb = new SqlConnectionStri
所以我使用 tidhttp 来发出 post 请求。当我尝试将 connectTimeout 设置为任意时间段时,它都没有效果。在出现异常之前我仍然等待约 5 秒。提前致谢! 最佳答案 如果您要连接到
如果我们不设置 ConnectTimeout 值,例如“Connect Timeout=60”,(在 SqlCommand 中都没有),它的默认值是多少?我被告知是 15 秒 谢谢 最佳答案 defa
如果你 curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15); 15 秒后没有建立连接,会发生什么? 最佳答案 根据 this mailing list
我正在尝试为 MongoClient(驱动程序版本 2.13)设置连接超时。 它挂起 10 秒,然后超时。我需要快速超时,因为此代码用于测试。 这是我的代码: String connectionUri
我正在做这个项目,其中一小部分是连接到服务器并做一些事情,如果它在一段时间内无法连接到服务器,则给出错误信息..我知道 curl 代码看起来像这样curl_easy_setopt(c,CURLOPT_
我发现,当为 TIdHTTP 组件设置 ConnectTimeoout 属性时,它会使请求(GET 和 POST)变慢约 120 毫秒? 这是为什么,我可以以某种方式避免/绕过它吗? Env:D201
我的connectTimeout和receiveTimeouts不起作用。这是我的代码: BaseOptions options = new BaseOptions( baseUrl:
我有一个通过 JQuery Ajax 请求的 Servlet。激活的过程需要花费大量时间来执行(最多 3-5 分钟)。我已将 server.xml 中的 connectTimeout 设置为“6000
我们的项目要求支持 Postgres(Postgresql 驱动程序)的“jdbc 超时”功能。我们还支持 Microsoft SQL(JTDS 驱动程序)和 MySQl(mysql 驱动程序)。所以
使用 SSL 时如何在 Indy 中设置 ConnectTimeout/ReadTimeout ? MCVE: program mcve; uses {$IFDEF UNIX}{$IFDEF Us
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: Receiving request timeout even though connect timeout and
当我将 ConnectTimeout 设置为 IdSMTP(例如,30 秒)并且 SMTP 服务器不可用时,它从 SMTP 服务器起飞大约 105 秒。 这是版本 10 中的 Indy 组件 - *2
我正在通过 SSH 发送命令。这个特定的命令恰好告诉机器重新启动。不幸的是,这会挂起我的 SSH session 并且不会返回,因此我的脚本无法继续转发到其他任务。 我已经尝试了各种修改命令本身的组合
我有 Spring Boot 基础设施,但微服务很少。他们彼此之间沟通得很好。其中一个微服务有一些第三方调用,通过http调用一些第三方服务。我已经定义了自己的 RestTemplate,并在 ini
因此,我一直在尝试使用 Azure 认知服务文本转语音 REST API 处理一个包含数千个文本文件的文件夹,将每个文件转换为语音。它工作得很好,直到它不起作用。多次成功转换后出现错误。我希望有一个稳
尝试通过客户端连接到 Azure Web App 上托管的 ChromaDB 实例时,我不断收到连接超时错误 import chromadb client = chromadb.HttpClient(
我们在 .NET Core 2.0 Azure 应用服务中偶然收到以下错误日志: StackExchange.Redis.RedisConnectionException: No connection
我们在 .NET Core 2.0 Azure 应用服务中偶然收到以下错误日志: StackExchange.Redis.RedisConnectionException: No connection
我是一名优秀的程序员,十分优秀!