在SqlCommand中,CommandTimeout实际上代表什么时间跨度?

时间:2018-10-11 08:21:08

标签: sql .net timeout sqldatareader sqlcommand

我正在使用' MENU FORM Public Class frmMenu Public Property FromForm As Form Private Sub btnMdr2_Click(sender As Object, e As EventArgs) Handles _ btnMdr2.Click FromForm = Me Dim mdr2Form As New ParentForm mdr2Form.Show() End Sub End Class 'PARENT FORM Public Class ParentForm Public Property FromForm As Form Public Sub MachineDailyReportForm_Load(sender As Object, e As EventArgs)_ Handles MyBase.Load FromForm = Me 'Show loading screen Dim loadingForm As New LoadingForm(FromForm) loadingForm.Show() 'Use For loop to delay the process(add data in list) and to see 'loading screen For i As Long = 0 To 1000000000 If i = 1000000000 Then Exit For Else Continue For End If Next Dim list As New List(Of String) machineList.Items.Add("Wheel") machineList.Items.Add("Range") machineList.Items.Add("Gear") 'Close loading screen loadingForm.CloseLoadingDialog() End Sub End Class 'LOADING FORM Public Class LoadingForm Public Property FromForm As Form Public Sub New(ByVal FromForm As Form) InitializeComponent() Me.FromForm = FromForm End Sub Public Sub SplashScreen_Load() Handles MyBase.Load PictureBoxGif.Image = My.Resources.loading Show() Refresh() End Sub Public Sub CloseLoadingDialog() Me.Close() Me.Dispose() End Sub End Class SqlConnectionSqlCommand查询Microsoft SQL数据库,就像在https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/retrieving-data-using-a-datareader中所述

现在,SqlReader允许设置SqlCommand,我正在这样做(简化):

CommandTimeout

我的问题是,超时实际上适用于什么?

  • using (SqlConnection connection = GetConnection()) { connection.Open(); using (SqlCommand command = connection.CreateCommand()) { command.CommandText = query; //My custom SQL query command.CommandType = CommandType.Text; //Set Timeout command.CommandTimeout = timeout.Value; //My custom timeout using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { //Read row by row and do stuff } } } } 中花费的时间
  • ExecuteReader()中花费的时间
  • 两者都是
  • 还有别的吗?

在MSDN和Web上似乎都没有专门的文档。

1 个答案:

答案 0 :(得分:1)

它将适用于针对数据库command.ExecuteReader()执行命令的时间,该时间在您开始读取记录时已完成。您可以通过在while之后插入一个断点并坐在那里来进行测试,以确保不会超时。