What is the difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout?

What is the difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout?

Is there any difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout in .NET?

 

回答1

Yes. CommandTimeout is how long a single command can take to complete. ConnectionTimeout is how long it can take to establish a connection to the server to start with.

For instance, you may be executing relatively long-running queries - it's perfectly okay for them to take 10 minutes to complete, but if it took 10 minutes to make the connection to start with, you'd know that something was badly wrong.

 

flipdoubt - the CommandTimeout will affect the query, the ConnectionTimout won't. The ConnectionTimout isn't a timeout for the connection to peform queries - it's just the timeout for the connection to connect to the database in the first place. – Robin Bennett Nov 5 '09 at 16:11

 

 

回答2

SqlCommand.CommandTimeout = timeout limit for your SQL query. Means, how much time a (eg: SELECT, UPDATE) query can take for its execution. If it exceeds SqlCommand.CommandTimeout, then it stops execution. A command timeout error will occur.

SqlConnection.ConnectionTimeout = timeout limit for your connection. Means, how much time your connection object can try to connect. If it exceeds the specified time, it stops connecting. A connection timeout error will occur.

 

 

 

 

作者:Chuck Lu    GitHub    
posted @   ChuckLu  阅读(77)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2020-06-21 Set-Cookie
2019-06-21 webstorm tools window
2019-06-21 What does the dot after dollar sign mean in jQuery when declaring variables?
2019-06-21 File upload with cropping support using Cropper --jquery file upload
2019-06-21 What is httpcontext
2019-06-21 foreach on Request.Files
2019-06-21 jQuery file upload测试
点击右上角即可分享
微信分享提示