什么是“连接超时"?在 sql server 连接字符串中? [英] What is "Connect Timeout" in sql server connection string?

查看:25
本文介绍了什么是“连接超时"?在 sql server 连接字符串中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下连接字符串(从 sql server 的属性中获取):

I have the following connection string(get from a property of sql server):

Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\myUser\Desktop\adoBanche\Banche\bin\Debug\banche.mdf;Integrated Security=True;Connect Timeout=30

我不明白 Timeout=30 是什么意思.有人能解释一下是什么意思吗?

I don't understand what mean Timeout=30. Someone could explain what means?

推荐答案

这是创建连接的超时,而不是在该连接上执行的命令的超时.

That is the timeout to create the connection, NOT a timeout for commands executed over that connection.

例如参见 http://www.connectionstrings.com/all-sql-server-connection-string-keywords/(注意属性是连接超时"(或连接超时"),而不仅仅是超时")

See for instance http://www.connectionstrings.com/all-sql-server-connection-string-keywords/ (note that the property is "Connect Timeout" (or "Connection Timeout"), not just "Timeout")

来自评论:

无法通过连接字符串设置命令超时.但是,SqlCommand 有一个 CommandTimeout属性(派生自 DbCommand),您可以在其中设置每个命令的超时时间(以秒为单位).

It is not possible to set the command timeout through the connection string. However, the SqlCommand has a CommandTimeout property (derived from DbCommand) where you can set a timeout (in seconds) per command.

请注意,当您使用 Read() 循环查询结果时,每次读取都会重置超时.超时是针对每个网络请求,而不是针对总连接数.

Do note that when you loop over query results with Read(), the timeout is reset on every read. The timeout is for each network request, not for the total connection.

这篇关于什么是“连接超时"?在 sql server 连接字符串中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆