我总是收到错误"超时已过期。超时时间过去了....."

时间:2015-10-08 06:41:46

标签: vb.net datagridview timeout settimeout

任何人都知道如何在下面的代码中添加连接超时? 我总是收到错误"timeout expired. the timeout period elapsed prior ..... "

Private Sub FillToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillToolStripButton.Click
    Try
        Me.SpLastTransactionTableAdapter.Fill(Me.VoyagerDataSet2.spLastTransaction, VaraccountToolStripTextBox.Text)
    Catch ex As System.Exception
        System.Windows.Forms.MessageBox.Show(ex.Message)
    End Try
End Sub

1 个答案:

答案 0 :(得分:1)

您可以使用SqlCommand.CommandTimeout属性设置等待时间,然后再终止尝试执行命令并生成错误。

请注意,SqlDataAdapter.SelectCommand是在SqlCommand期间使用的Fill,用于从数据库中选择记录以放置在DataSet中,因此您可以使用:

Me.SpLastTransactionTableAdapter.SelectCommand.CommandTimeout = 1000
Me.SpLastTransactionTableAdapter.Fill(Me.VoyagerDataSet2.spLastTransaction, VaraccountToolStripTextBox.Text)
相关问题